コード例 #1
0
ファイル: logic.py プロジェクト: EnviDat/ckanext-passwordless
def _create_user(email):
    # first check temporary quota
    _check_new_user_quota()

    try:
        data_dict = {
            'email': email.lower(),
            'fullname': util.generate_user_fullname(email),
            'name': _get_new_username(email),
            'password': util.generate_password()
        }
        user = toolkit.get_action('user_create')(context={
            'ignore_auth': True
        },
                                                 data_dict=data_dict)
    except sqlalchemy.exc.InternalError as error:
        exception_message = "{0}".format(error)
        log.error("failed to create user: {0}".format(error))
        if exception_message.find("quota") >= 0:
            raise DataError(
                "error creating a new user, daily new user quota exceeded")
        else:
            raise DataError("internal error creating a new user")

    return user
コード例 #2
0
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct'''
        surplus_keys_schema = [
            'id', 'publisher_id', 'user_id', 'config', 'save'
        ]
        schema_keys = harvest_source_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        # user_id is not yet used, we'll set the logged user one for the time being
        if not data_dict.get('user_id', None):
            if c.userobj:
                data_dict['user_id'] = c.userobj.id
        if keys_in_schema - set(data_dict.keys()):
            log.info(_('Incorrect form fields posted'))
            raise DataError(data_dict)
コード例 #3
0
def tuplize_dict(data_dict):
    ''' gets a dict with keys of the form 'table__0__key' and converts them
    to a tuple like ('table', 0, 'key').

    May raise a DataError if the format of the key is incorrect.
    '''

    tuplized_dict = {}
    for key, value in data_dict.iteritems():
        key_list = key.split('__')
        for num, key in enumerate(key_list):
            if num % 2 == 1:
                try:
                    key_list[num] = int(key)
                except ValueError:
                    raise DataError('Bad key')
        tuplized_dict[tuple(key_list)] = value
    return tuplized_dict
コード例 #4
0
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct, mostly for checking out if
        spammers are submitting only part of the form'''

        # Resources might not exist yet (eg. Add Dataset)
        surplus_keys_schema = ['__extras', '__junk', 'state', 'groups',
                               'extras_validation', 'save', 'return_to',
                               'resources']

        schema_keys = package_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        missing_keys = keys_in_schema - set(data_dict.keys())

        if missing_keys:
            #print data_dict
            #print missing_keys
            log.info('incorrect form fields posted')
            raise DataError(data_dict)
コード例 #5
0
ファイル: logic.py プロジェクト: microcomp/ckanext-cas
def user_provision(context, data_dict):
    _check_access('user_provision', context, data_dict)
    actor = _create_user(data_dict, 'Actor')
    log.info('actor processed')
    subject = _create_user(data_dict, 'Subject')
    log.info('subject processed')
    #TODO vytvaranie organizacie a zaclenenie
    spr_roles = data_dict.get('SPR.Roles', '')
    subject_id = data_dict['Subject.UPVSIdentityID']
    actor_id = data_dict['Actor.UPVSIdentityID']
    if 'MOD-R-PO' in spr_roles:
        org_id = data_dict['Subject.UPVSIdentityID']
        org_name = data_dict.get('Subject.Username',
                                 data_dict['Subject.UPVSIdentityID'])
        org_title = data_dict['Subject.FormattedName']
        create_organization(org_id, org_name, org_title)
    if actor and subject:
        return True
    raise DataError('Unable to provision user')
コード例 #6
0
def organization_list(context, data_dict):
    '''
    Overriding the `organization_list` action,
    See github issue #353
    To replace the bcgov ckan fork modification from https://github.com/bcgov/ckan/pull/16
    '''

    toolkit.check_access('organization_list', context, data_dict)
    groups = data_dict.get('organizations', 'None')

    try:
        import ast
        data_dict['groups'] = ast.literal_eval(groups)
    except Exception as e:
        from ckan.lib.navl.dictization_functions import DataError
        raise DataError('organizations is not parsable, each value must have double or single quotes.')

    data_dict.setdefault('type', 'organization')
    return _group_or_org_list(context, data_dict, is_org=True)
コード例 #7
0
ファイル: __init__.py プロジェクト: usuariobkp/ckan
def tuplize_dict(data_dict):
    '''Takes a dict with keys of the form 'table__0__key' and converts them
    to a tuple like ('table', 0, 'key').

    Dict should be put through parse_dict before this function, to have
    values standardized.

    May raise a DataError if the format of the key is incorrect.
    '''
    tuplized_dict = {}
    for key, value in data_dict.iteritems():
        key_list = key.split('__')
        for num, key in enumerate(key_list):
            if num % 2 == 1:
                try:
                    key_list[num] = int(key)
                except ValueError:
                    raise DataError('Bad key')
        tuplized_dict[tuple(key_list)] = value
    return tuplized_dict
コード例 #8
0
 def _size_check(self, key, value):
     if key in SIZE_CHECK_KEYS and value is not None and len(
             value) >= MAX_SIZE:
         raise DataError(
             '%s: Maximum allowed size is %i. Actual size is %i.' %
             (key, MAX_SIZE, len(value)))