def account_notifications(include_read=False): """ List notifications for the currently logged in user. :param bool include_read: include read notifications. if False, only return unread ones. :return: list of Notification """ username = getCurrentUserName() api = get_backend_users_proxy() return api.notification_list(username, include_read)
def topology_create(): """ Creates an empty topology. Return value: The return value of this method is the info dict of the new topology as returned by :py:func:`topology_info`. This info dict also contains the topology id that is needed for further manipulation of that object. """ getCurrentUserInfo().check_may_create_topologies() return TopologyInfo.create(getCurrentUserName())
def account_notification_set_all_read(read): """ Modify the read status of all notifications :param bool read: new read status of the notification :return: None """ username = getCurrentUserName() api = get_backend_users_proxy() api.notification_set_all_read(username, read) get_user_info(username).invalidate_info()
def notifyAdmins(subject, text, global_contact = True, issue="admin"): """ Request assistence by sending a notification to all AdminContact or HostContact users. :param subject: notification subject :param text: notification body :param global_contact: if True, send to Global*Contact. Otherwise to Orga*Contact. :param issue: if issue is "admin", the notification is sent to *AdminContact. Otherwise, it is sent to *HostContact. :return: """ user_orga = getCurrentUserInfo().get_organization_name() user_name = getCurrentUserName() get_backend_core_proxy().notifyAdmins(subject, text, global_contact, issue, user_orga, user_name)
def account_send_notification(name, subject, message, ref=None, from_support=False, subject_group=None): """ Sends an email to the account and also sends a message via the internal message system :param str ref arbitrary string for referencing :param str subject_group arbitrary string to reference desired subject_group for this message """ if from_support: fromUser = None else: fromUser = getCurrentUserName() getCurrentUserInfo().check_may_send_message_to_user(get_user_info(name)) api = get_backend_users_proxy() api.send_message(name, subject, message, fromUser=fromUser, ref=ref, subject_group=subject_group)
def account_modify(name=None, attrs=None, ignore_key_on_unauthorized=False, ignore_flag_on_unauthorized=False): """ Modifies the given account, configuring it with the given attributes. Parameter *name*: If this parameter is given, the given user will be modified. Otherwise the currently logged in user will be modified. Note that only users with the flag ``admin`` are permitted to modify other accounts. Parameter *attrs*: This field contains a dict of attributes to set/overwrite on the account. Users can change the following fields of their own accounts: ``realname``, ``affiliation``, ``password`` and ``email``. Administrators (i.e. users with flag ``admin``) can additionally change these fields on all accounts: ``name``, ``origin`` and ``flags``. ``flags`` must be a dictionary of the form {flag_name: is_set}. if is_set is true, the respective flag will be set. if is_set is false, it will be unset. if a flag is not mentioned in the dict, it is left as it is. Parameter *ignore_key_on_unauthorized*: Defines the behavior when ``attrs`` contains a key that the current user is not allowed to modify: If True, the key is simply skipped, and the other keys are still modified. If False, the whole operation will be cancelled. Parameter *ignore_flag_on_unauthorized*: Similar to ``ingnore_key_on_unauthorized``, but with the ``flags`` attribute Return value: This method returns the info dict of the account. All changes will be reflected in this dict. """ if not attrs: attrs = {} if name is None: name = getCurrentUserName() target_account = get_user_info(name) modify_keys_allowed_list = getCurrentUserInfo().modify_user_allowed_keys( target_account) modify_flags_allowed = getCurrentUserInfo().modify_user_allowed_flags( target_account) attrs = PermissionChecker.reduce_keys_to_allowed( attrs, modify_keys_allowed_list, modify_flags_allowed, ignore_key_on_unauthorized, ignore_flag_on_unauthorized) return target_account.modify(attrs) #fixme: return keys to allowed ones
def account_info(name=None): """ Retrieves information about an account. Parameter *name*: If this parameter is given, information about the given account will be returned. Otherwise information about the current user will be returned. Return value: The return value of this method is a dict containing the following information about the account: ``name`` The name of the account. ``origin`` The origin of the account. ``id`` The unique id of the account in the format ``Name@Origin``. ``flags`` The flags of the account. ``realname`` The real name of the account holder. ``affiliation`` The affiliation of the account holder, e.g. university, company, etc. ``email`` The email address of the account holder. This address wil be used to send important notifications. Exceptions: If the given account does not exist an exception is raised. """ if name is None: name = getCurrentUserName() target_account = get_user_info(name) keys_to_show = getCurrentUserInfo().account_info_visible_keys( target_account) info = target_account.info(update=True) for k in info.keys(): if k not in keys_to_show and not k.startswith("_"): #fixme: move key restriction to permission checker del info[k] return info
def broadcast_announcement(title, message, ref=None, show_sender=True, subject_group=None, organization_filter=None): """ takes a list of filters to broadcast a message. sends one message to each user who matches at least one filter. :param str title: message subject :param str message: message body :param NoneType or tuple(str, str) ref: ref pair :param bool show_sender Either sender is shown as sender or field is marked with 'None' :param NoneType or str subject_group: subject group :param NoneType or list(tuple) filters: list of pairs (organization, flag). if this is None, send to every user. """ getCurrentUserInfo().check_may_broadcast_messages(organization_filter) api = get_backend_users_proxy() api.broadcast_message(title, message, fromUser=(getCurrentUserName() if show_sender else None), ref=ref, subject_group=subject_group, organization_filter=organization_filter)
def account_info(name=None): """ Retrieves information about an account. Parameter *name*: If this parameter is given, information about the given account will be returned. Otherwise information about the current user will be returned. Return value: The return value of this method is a dict containing the following information about the account: ``name`` The name of the account. ``origin`` The origin of the account. ``id`` The unique id of the account in the format ``Name@Origin``. ``flags`` The flags of the account. ``realname`` The real name of the account holder. ``affiliation`` The affiliation of the account holder, e.g. university, company, etc. ``email`` The email address of the account holder. This address wil be used to send important notifications. Exceptions: If the given account does not exist an exception is raised. """ if name is None: name = getCurrentUserName() target_account = get_user_info(name) keys_to_show = getCurrentUserInfo().account_info_visible_keys(target_account) info = target_account.info(update=True) for k in info.keys(): if k not in keys_to_show and not k.startswith("_"): #fixme: move key restriction to permission checker del info[k] return info
def account_remove(name=None): """ Deletes the given account from the database. Note that this does not remove the entry in any external user database. Thus the user can still login which will create a new account. Parameter *name*: This field must contain the user name of the account to be removed. Return value: This method returns nothing if the account has been deleted. """ if name is None: name = getCurrentUserName() target_account = get_user_info(name) getCurrentUserInfo().check_may_delete_user(target_account) target_account.remove()
def account_modify(name=None, attrs=None, ignore_key_on_unauthorized=False, ignore_flag_on_unauthorized=False): """ Modifies the given account, configuring it with the given attributes. Parameter *name*: If this parameter is given, the given user will be modified. Otherwise the currently logged in user will be modified. Note that only users with the flag ``admin`` are permitted to modify other accounts. Parameter *attrs*: This field contains a dict of attributes to set/overwrite on the account. Users can change the following fields of their own accounts: ``realname``, ``affiliation``, ``password`` and ``email``. Administrators (i.e. users with flag ``admin``) can additionally change these fields on all accounts: ``name``, ``origin`` and ``flags``. ``flags`` must be a dictionary of the form {flag_name: is_set}. if is_set is true, the respective flag will be set. if is_set is false, it will be unset. if a flag is not mentioned in the dict, it is left as it is. Parameter *ignore_key_on_unauthorized*: Defines the behavior when ``attrs`` contains a key that the current user is not allowed to modify: If True, the key is simply skipped, and the other keys are still modified. If False, the whole operation will be cancelled. Parameter *ignore_flag_on_unauthorized*: Similar to ``ingnore_key_on_unauthorized``, but with the ``flags`` attribute Return value: This method returns the info dict of the account. All changes will be reflected in this dict. """ if not attrs: attrs = {} if name is None: name = getCurrentUserName() target_account = get_user_info(name) modify_keys_allowed_list = getCurrentUserInfo().modify_user_allowed_keys(target_account) modify_flags_allowed = getCurrentUserInfo().modify_user_allowed_flags(target_account) attrs = PermissionChecker.reduce_keys_to_allowed(attrs, modify_keys_allowed_list, modify_flags_allowed, ignore_key_on_unauthorized, ignore_flag_on_unauthorized) return target_account.modify(attrs)
def account_create(username, password, organization, attrs=None): """ This method will create a new account in a provider that supports this. Note that this method like all others is only available for registered users. Backend configurations should include a guest account to enable user registration. Parameter *username*: This field must contain the requested user name of the new user. Parameter *password*: This field must contain the password for the new user. Parameter *attrs*: This field can contain additional attributes for the account like the ones accepted in :py:func:`account_modify`. Parameter *provider*: If multiple providers support account registration, this field can be used to create the account in one specific provider. If this field is not given, all providers will be queried in turn. Return value: This method returns the info dict of the new account. """ if getCurrentUserName() is None: attrs = PermissionChecker.reduce_keys_to_allowed( attrs, PermissionChecker.account_register_self_allowed_keys(), []) else: target_user = get_pseudo_user_info(username, organization) getCurrentUserInfo().check_may_create_user(target_user) attrs = PermissionChecker.reduce_keys_to_allowed( attrs, getCurrentUserInfo().modify_user_allowed_keys(target_user), getCurrentUserInfo().modify_user_allowed_flags(target_user)) email = attrs.get('email', None) del attrs['email'] # fixme: email should be an api parameter here return UserInfo.create(username, organization, email, password, attrs) #fixme: reduce key to allowed ones
def account_create(username, password, organization, attrs=None): """ This method will create a new account in a provider that supports this. Note that this method like all others is only available for registered users. Backend configurations should include a guest account to enable user registration. Parameter *username*: This field must contain the requested user name of the new user. Parameter *password*: This field must contain the password for the new user. Parameter *attrs*: This field can contain additional attributes for the account like the ones accepted in :py:func:`account_modify`. Parameter *provider*: If multiple providers support account registration, this field can be used to create the account in one specific provider. If this field is not given, all providers will be queried in turn. Return value: This method returns the info dict of the new account. """ if getCurrentUserName() is None: attrs = PermissionChecker.reduce_keys_to_allowed(attrs, PermissionChecker.account_register_self_allowed_keys(), []) else: target_user = get_pseudo_user_info(username, organization) getCurrentUserInfo().check_may_create_user(target_user) attrs = PermissionChecker.reduce_keys_to_allowed(attrs, getCurrentUserInfo().modify_user_allowed_keys(target_user), getCurrentUserInfo().modify_user_allowed_flags(target_user)) email = attrs.get('email', None) del attrs['email'] # fixme: email should be an api parameter here return UserInfo.create(username, organization, email, password, attrs)
def topology_list(full=False, showAll=False, organization=None): #@ReservedAssignment """ Retrieves information about all topologies the user can access. Parameter *full*: See :py:func:`~topology_info` for this parameter. Return value: A list with information entries of all topologies. Each list entry contains exactly the same information as returned by :py:func:`topology_info`. If no topologies exist, the list is empty. """ if organization: getCurrentUserInfo().check_may_list_organization_topologies(organization) if showAll: getCurrentUserInfo().check_may_list_all_topologies() return get_topology_list(full, organization_filter=organization, username_filter=(None if showAll else getCurrentUserName()))