Esempio n. 1
0
def user_show_minimal(context, data_dict):
    '''Return a user account.

    Either the ``id`` or the ``user_obj`` parameter must be given.

    :param id: the id or name of the user (optional)
    :type id: string
    :param user_obj: the user dictionary of the user (optional)
    :type user_obj: user dictionary

    :rtype: dictionary

    '''
    result_dict = get.user_show(context, data_dict)
    if check_logged_in(context):
        for result in result_dict['datasets']:
            fulltext = _get_fulltext(result['id'])
            if fulltext:
                fulltext_dict = { 'key': 'full_text_search',
                                  'value': fulltext.text
                                }
                result['extras'].append(fulltext_dict) 
        return result_dict
    new_packages = []
    for result in result_dict['datasets']:
        new_package = _del_extra_field_from_dict(result)
        new_package = _del_main_field_from_dict(new_package)
        new_packages.append(new_package)
    result_dict['datasets'] = new_packages
    return result_dict
Esempio n. 2
0
def organization_create(context, data_dict):

    # When creating an organization, if the user is not a sysadmin it will be
    # created as pending, and sysadmins notified

    org_dict = create_core.organization_create(context, data_dict)

    # We create an organization as usual because we can't set
    # state=approval_needed on creation step and then
    # we patch the organization

    notify_sysadmins = False
    user = get_core.user_show(context, {'id': context['user']})
    if not user['sysadmin']:
        # Not a sysadmin, create as pending and notify sysadmins (if all went
        # well)
        context['__unhcr_state_pending'] = True
        org_dict = patch_core.organization_patch(context, {
            'id': org_dict['id'],
            'state': 'approval_needed'
        })
        notify_sysadmins = True

    if notify_sysadmins:
        try:
            mail_data_container_request_to_sysadmins(context, org_dict)
        except MailerException:
            message = '[email] Data container request notification is not sent: {0}'
            log.critical(message.format(org_dict['title']))

    return org_dict
Esempio n. 3
0
def user_show_minimal(context, data_dict):
    '''Return a user account.

    Either the ``id`` or the ``user_obj`` parameter must be given.

    :param id: the id or name of the user (optional)
    :type id: string
    :param user_obj: the user dictionary of the user (optional)
    :type user_obj: user dictionary

    :rtype: dictionary

    '''
    result_dict = get.user_show(context, data_dict)
    if check_logged_in(context):
        for result in result_dict['datasets']:
            fulltext = _get_fulltext(result['id'])
            if fulltext:
                fulltext_dict = {
                    'key': 'full_text_search',
                    'value': fulltext.text
                }
                result['extras'].append(fulltext_dict)
        return result_dict
    new_packages = []
    for result in result_dict['datasets']:
        new_package = _del_extra_field_from_dict(result)
        new_package = _del_main_field_from_dict(new_package)
        new_packages.append(new_package)
    result_dict['datasets'] = new_packages
    return result_dict
Esempio n. 4
0
def show_user(context, data_dict):
    # this function solves the missing value error
    # when dataset schema is changed and we have old datasets
    # that were created prior to the schema change

    if not context.get('save', None):
        context['validate'] = False

    return user_show(context, data_dict)
Esempio n. 5
0
def user_show(context, data_dict):
    '''
    Return a user account and extra profile info.

    Minor rewrite to add additional user profile information (acquired eg. from
    shibboleth) from the user_extra table to the c.user_dict for templates.
    NOTE: 'revision_show' method still references to default
    ckan.logic.action.get.revision_show while 'package_show' declaration is
    resolved with standard 'get_action' hook. Not sure which to use so these
    are tried.

    Either the ``id`` or the ``user_obj`` parameter must be given in data_dict.

    :param id: the id or name of the user (optional)
    :type id: string
    :param user_obj: the user dictionary of the user (optional)
    :type user_obj: user dictionary

    :rtype: dictionary

    '''
    # In some places, this user_show is used almost like a check access function
    # thus we are returning something instead of modifying the authorisation function
    if context.get('user', '') == data_dict.get('id', None):
        hide = False
    elif context.get('user', False) and new_authz.is_sysadmin(context['user']):
        hide = False
    # Dashboard:
    elif data_dict.get('user_obj', False) and not data_dict.get('id', False) and \
            (context.get('user', '') == data_dict['user_obj'].name):
        hide = False
    else:
        hide = True

    user_dict = get.user_show(context, data_dict)

    # Added in ckanext-shibboleth
    extra_dict = utils.fetch_user_extra(user_dict['id'])
    user_dict.update(extra_dict)

    if hide:
        return {
            'name': user_dict.get('name', ''),
            'about': user_dict.get('about', ''),
            'id': user_dict.get('id', '')
        }

    return user_dict
Esempio n. 6
0
def user_show(context, data_dict):
    '''
    Return a user account and extra profile info.

    Minor rewrite to add additional user profile information (acquired eg. from
    shibboleth) from the user_extra table to the c.user_dict for templates.
    NOTE: 'revision_show' method still references to default
    ckan.logic.action.get.revision_show while 'package_show' declaration is
    resolved with standard 'get_action' hook. Not sure which to use so these
    are tried.

    Either the ``id`` or the ``user_obj`` parameter must be given in data_dict.

    :param id: the id or name of the user (optional)
    :type id: string
    :param user_obj: the user dictionary of the user (optional)
    :type user_obj: user dictionary

    :rtype: dictionary

    '''
    # In some places, this user_show is used almost like a check access function
    # thus we are returning something instead of modifying the authorisation function
    if context.get('user', '') == data_dict.get('id', None):
        hide = False
    elif context.get('user', False) and new_authz.is_sysadmin(context['user']):
        hide = False
    # Dashboard:
    elif data_dict.get('user_obj', False) and not data_dict.get('id', False) and \
            (context.get('user', '') == data_dict['user_obj'].name):
        hide = False
    else:
        hide = True

    user_dict = get.user_show(context, data_dict)

    # Added in ckanext-shibboleth
    extra_dict = utils.fetch_user_extra(user_dict['id'])
    user_dict.update(extra_dict)

    if hide:
        return {'name': user_dict.get('name', ''),
                'about': user_dict.get('about', ''),
                'id': user_dict.get('id', '')}

    return user_dict
Esempio n. 7
0
def user_show(context, data_dict):
    user_dict = get_core.user_show(context, data_dict)
    is_sysadmin = authz.is_sysadmin(g.user)
    if not is_sysadmin and user_dict['state'] == "deleted":
        raise NotFound(_("User not found"))
    return user_dict
Esempio n. 8
0
def user_show(context, data_dict):
    user_dict = user_get.user_show(context, data_dict)
    if user_dict:
        _set_user_names(context, user_dict)
    return user_dict