diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-18 17:59:50 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2012-09-18 17:59:50 +0200 |
commit | 6130a2377ca6754fee88773097ce220abef1aa47 (patch) | |
tree | 76bea0d76393100fcf393c164c96d34f286aba7a /module/datatypes/User.py | |
parent | Added DuckcryptInfo decrypter, smaller fixes (diff) | |
parent | dropdowns in navbar (diff) | |
download | pyload-6130a2377ca6754fee88773097ce220abef1aa47.tar.xz |
merged stable into default
Diffstat (limited to 'module/datatypes/User.py')
-rw-r--r-- | module/datatypes/User.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/module/datatypes/User.py b/module/datatypes/User.py new file mode 100644 index 000000000..d48111182 --- /dev/null +++ b/module/datatypes/User.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +############################################################################### +# Copyright(c) 2008-2012 pyLoad Team +# http://www.pyload.org +# +# This file is part of pyLoad. +# pyLoad is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Subjected to the terms and conditions in LICENSE +# +# @author: RaNaN +############################################################################### + + +from module.Api import UserData, Permission, Role, has_permission + +#TODO: activate user +#noinspection PyUnresolvedReferences +class User(UserData): + + @staticmethod + def fromUserData(api, user): + return User(api, user.uid, user.name, user.email, user.role, user.permission, user.folder, + user.traffic, user.dllimit, user.dlquota, user.hddquota, user.user, user.templateName) + + def __init__(self, api, *args): + UserData.__init__(self, *args) + self.api = api + + + def toUserData(self): + return UserData() + + def hasPermission(self, perms): + """ Accepts permission bit or name """ + + if isinstance(perms, basestring) and hasattr(Permission, perms): + perms = getattr(Role, perms) + + return has_permission(self.permission, perms) + + def hasRole(self, role): + if isinstance(role, basestring) and hasattr(Role, role): + role = getattr(Role, role) + + return self.role == role + + def isAdmin(self): + return self.hasRole(Role.Admin) + + @property + def handle(self): + """ Internal user handle used for most operations (secondary share handle with primary user) """ + if self.hasRole(Role.Admin): + return None + return self.user if self.user else self.uid |