Beispiel #1
0
def load_user_info(toyz_settings, tid, params):
    """
    Load info for a given user from the database
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id or group_id (*string* ): User or group to load parameters for
        - user_attr (*list* ): List of user attributes to load
    
    Response
        - id: 'user_info'
        - Each attribute requested by the client is also returned as a key in the
          response
    """
    user = core.get_user_type(params)
    fields = params['user_attr']
    response = {
        'id': 'user_info'
    }
    for field in fields:
        if field in params['user_attr']:
            response[field] = db_utils.get_param(toyz_settings.db, field, **user)
    return response
Beispiel #2
0
def load_user_info(toyz_settings, tid, params):
    """
    Load info for a given user from the database
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id or group_id (*string* ): User or group to load parameters for
        - user_attr (*list* ): List of user attributes to load
    
    Response
        - id: 'user_info'
        - Each attribute requested by the client is also returned as a key in the
          response
    """
    user = core.get_user_type(params)
    fields = params['user_attr']
    response = {'id': 'user_info'}
    for field in fields:
        if field in params['user_attr']:
            response[field] = db_utils.get_param(toyz_settings.db, field,
                                                 **user)
    return response
Beispiel #3
0
def save_user_info(toyz_settings, tid, params):
    """
    Save a users info. If any admin settings are being changed, ensures that the user
    is in the admin group.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params can be any settings the user has permission to set on the server.
    
    Response
        - id: 'notification'
        - func: 'save_user_info'
        - msg: 'Settings saved for <user_id>'
    """
    groups = db_utils.get_param(toyz_settings.db, 'groups', user_id=tid['user_id'])
    # check that user is in the admin group
    if 'paths' in params and tid['user_id']!='admin' and 'admin' not in groups:
        raise ToyzJobError("You must be in the admin group to modify path permissions")
    
    if (('modules' in params or 'toyz' in params or 'third_party' in params) and 
            tid['user_id']!='admin' and 'admin' not in groups and 'modify_toyz' not in groups):
        raise ToyzJobError(
            "You must be an administrator or belong to the 'modify_toyz' "
            "group to modify a users toyz or module access")
    
    # Conditions is a dict that contains any conditional parameters from a gui
    # parameter list. We don't use any of those for this function, so we remove them
    if 'conditions' in params:
        del params['conditions']
    
    user = core.get_user_type(params)
    #update_fields = dict(params)
    #if 'user_id' in params:
    #    del update_fields['user_id']
    #elif 'group_id' in params:
    #   del update_fields['group_id']
    for field in params:
        if field in db_utils.param_formats:
            field_dict = {field: params[field]}
            field_dict.update(user)
            db_utils.update_all_params(toyz_settings.db, field, **field_dict)
    
    if 'user_id' in user:
        msg = params['user_id']
    else:
        msg = params['group_id']
    
    response = {
        'id': 'notification',
        'func': 'save_user_info',
        'msg': 'Settings saved for '+ msg
    }
    
    return response
Beispiel #4
0
def reset_pwd(toyz_settings, tid, params):
    """
    Reset a users password
    """
    user = core.get_user_type(params)
    if 'user_id' in params:
        user_id = params['user_id']
    elif 'group_id' in params:
        user_id = group_id
    else:
        raise ToyzJobError("Must specify a user_id or group_id to reset password")
    pwd_hash = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd_hash, **user)
    
    response = {
        'id': 'notification',
        'func': 'reset_pwd',
        'msg': 'Password reset successfully',
    }
    return response
Beispiel #5
0
def reset_pwd(toyz_settings, tid, params):
    """
    Reset a users password
    """
    user = core.get_user_type(params)
    if 'user_id' in params:
        user_id = params['user_id']
    elif 'group_id' in params:
        user_id = group_id
    else:
        raise ToyzJobError(
            "Must specify a user_id or group_id to reset password")
    pwd_hash = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd_hash, **user)

    response = {
        'id': 'notification',
        'func': 'reset_pwd',
        'msg': 'Password reset successfully',
    }
    return response
Beispiel #6
0
def add_new_user(toyz_settings, tid, params):
    """
    Add a new user to the toyz application.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id (*string* ): Id of user to add
    
    Response
        - id: 'notification'
        - func: 'add_new_user'
        - msg: 'User/Group added correctly'
    """
    user = core.get_user_type(params)
    user_id = six.next(six.itervalues(user))
    pwd = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd, **user)
    if 'user_id' in user:
        # set permissions and shortcuts for users home path
        core.check_user_shortcuts(toyz_settings, **user)
        # Add user to all users
        db_utils.update_param(toyz_settings.db, 'users', group_id='all', users=[user['user_id']])
        msg = 'User added correctly'
    else:
        msg = 'Group added correctly'
    
    response = {
        'id': 'notification',
        'func': 'add_new_user',
        'msg': msg
    }
    return response
Beispiel #7
0
def add_new_user(toyz_settings, tid, params):
    """
    Add a new user to the toyz application.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params
        - user_id (*string* ): Id of user to add
    
    Response
        - id: 'notification'
        - func: 'add_new_user'
        - msg: 'User/Group added correctly'
    """
    user = core.get_user_type(params)
    user_id = six.next(six.itervalues(user))
    pwd = core.encrypt_pwd(toyz_settings, user_id)
    db_utils.update_param(toyz_settings.db, 'pwd', pwd=pwd, **user)
    if 'user_id' in user:
        # set permissions and shortcuts for users home path
        core.check_user_shortcuts(toyz_settings, **user)
        # Add user to all users
        db_utils.update_param(toyz_settings.db,
                              'users',
                              group_id='all',
                              users=[user['user_id']])
        msg = 'User added correctly'
    else:
        msg = 'Group added correctly'

    response = {'id': 'notification', 'func': 'add_new_user', 'msg': msg}
    return response
Beispiel #8
0
def save_user_info(toyz_settings, tid, params):
    """
    Save a users info. If any admin settings are being changed, ensures that the user
    is in the admin group.
    
    Parameters
        - toyz_settings ( :py:class:`toyz.utils.core.ToyzSettings`): Settings for the toyz 
          application
        - tid (*string* ): Task ID of the client user running the task
        - params (*dict* ): Any parameters sent by the client (see *params* below)
    
    Params can be any settings the user has permission to set on the server.
    
    Response
        - id: 'notification'
        - func: 'save_user_info'
        - msg: 'Settings saved for <user_id>'
    """
    groups = db_utils.get_param(toyz_settings.db,
                                'groups',
                                user_id=tid['user_id'])
    # check that user is in the admin group
    if 'paths' in params and tid[
            'user_id'] != 'admin' and 'admin' not in groups:
        raise ToyzJobError(
            "You must be in the admin group to modify path permissions")

    if (('modules' in params or 'toyz' in params or 'third_party' in params)
            and tid['user_id'] != 'admin' and 'admin' not in groups
            and 'modify_toyz' not in groups):
        raise ToyzJobError(
            "You must be an administrator or belong to the 'modify_toyz' "
            "group to modify a users toyz or module access")

    # Conditions is a dict that contains any conditional parameters from a gui
    # parameter list. We don't use any of those for this function, so we remove them
    if 'conditions' in params:
        del params['conditions']

    user = core.get_user_type(params)
    #update_fields = dict(params)
    #if 'user_id' in params:
    #    del update_fields['user_id']
    #elif 'group_id' in params:
    #   del update_fields['group_id']
    for field in params:
        if field in db_utils.param_formats:
            field_dict = {field: params[field]}
            field_dict.update(user)
            db_utils.update_all_params(toyz_settings.db, field, **field_dict)

    if 'user_id' in user:
        msg = params['user_id']
    else:
        msg = params['group_id']

    response = {
        'id': 'notification',
        'func': 'save_user_info',
        'msg': 'Settings saved for ' + msg
    }

    return response