summaryrefslogtreecommitdiffstats
path: root/pyload/api
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/api')
-rw-r--r--pyload/api/AccountApi.py58
1 files changed, 37 insertions, 21 deletions
diff --git a/pyload/api/AccountApi.py b/pyload/api/AccountApi.py
index 999484974..144074d3c 100644
--- a/pyload/api/AccountApi.py
+++ b/pyload/api/AccountApi.py
@@ -1,44 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from pyload.Api import Api, RequirePerm, Permission
-
+from pyload.Api import Api, RequirePerm, Permission, Conflict
from ApiComponent import ApiComponent
class AccountApi(ApiComponent):
""" All methods to control accounts """
+ @RequirePerm(Permission.All)
+ def getAccountTypes(self):
+ """All available account types.
+
+ :return: string list
+ """
+ return self.core.pluginManager.getPlugins("accounts").keys()
+
@RequirePerm(Permission.Accounts)
- def getAccounts(self, refresh):
+ def getAccounts(self):
"""Get information about all entered accounts.
- :param refresh: reload account info
:return: list of `AccountInfo`
"""
- accs = self.core.accountManager.getAllAccounts(refresh)
- accounts = []
- for plugin in accs.itervalues():
- accounts.extend([acc.toInfoData() for acc in plugin.values()])
+ accounts = self.core.accountManager.getAllAccounts(self.primaryUID)
+ return [acc.toInfoData() for acc in accounts]
- return accounts
-
- @RequirePerm(Permission.All)
- def getAccountTypes(self):
- """All available account types.
+ @RequirePerm(Permission.Accounts)
+ def getAccountInfo(self, plugin, loginname, refresh=False):
+ """ Returns :class:`AccountInfo` for a specific account
- :return: string list
+ :param refresh: reload account info
"""
- return self.core.pluginManager.getPlugins("accounts").keys()
+ account = self.core.accountManager.getAccount(plugin, loginname)
+
+ # Admins can see and refresh accounts
+ if not account or (self.primaryUID and self.primaryUID != account.owner):
+ return None
+
+ if refresh:
+ # reload account in place
+ account.getAccountInfo(True)
+
+ return account.toInfoData()
@RequirePerm(Permission.Accounts)
- def updateAccount(self, plugin, login, password):
- """Changes pw/options for specific account."""
- # TODO: options
- self.core.accountManager.updateAccount(plugin, login, password, {})
+ def updateAccount(self, plugin, loginname, password):
+ """Creates an account if not existent or updates the password
+
+ :return: newly created or updated account info
+ """
+ return self.core.accountManager.updateAccount(plugin, loginname, password, self.user).toInfoData()
+
+ @RequirePerm(Permission.Accounts)
def updateAccountInfo(self, account):
- """ Update account from :class:`AccountInfo` """
+ """ Update account settings from :class:`AccountInfo` """
#TODO
@RequirePerm(Permission.Accounts)
@@ -47,7 +63,7 @@ class AccountApi(ApiComponent):
:param account: :class:`ÀccountInfo` instance
"""
- self.core.accountManager.removeAccount(account.plugin, account.loginname)
+ self.core.accountManager.removeAccount(account.plugin, account.loginname, self.primaryUID)
if Api.extend(AccountApi):