Example #1
0
def logged_user():
    """Current logged user informations in JSON."""
    if current_user.is_anonymous:
        return jsonify({})

    user = current_user_record

    if user and 'resolve' in request.args:
        user = user.replace_refs()

    data = {
        'settings': {
            'document_identifier_link': current_app.config \
                .get('SONAR_APP_DOCUMENT_IDENTIFIER_LINK')
        }
    }

    if user:
        data['metadata'] = user.dumps()
        data['metadata']['is_superuser'] = user.is_superuser
        data['metadata']['is_admin'] = user.is_admin
        data['metadata']['is_moderator'] = user.is_moderator
        data['metadata']['is_submitter'] = user.is_submitter
        data['metadata']['is_user'] = user.is_user
        data['metadata']['permissions'] = {
            'users': {
                'add': UserPermission.create(user),
                'list': UserPermission.list(user)
            },
            'documents': {
                'add': DocumentPermission.create(user),
                'list': DocumentPermission.list(user)
            },
            'organisations': {
                'add': OrganisationPermission.create(user),
                'list': OrganisationPermission.list(user)
            },
            'deposits': {
                'add': DepositPermission.create(user),
                'list': DepositPermission.list(user)
            },
            'projects': {
                'add': RecordPermissionPolicy('create').can(),
                'list': RecordPermissionPolicy('search').can()
            },
            'collections': {
                'add': CollectionPermission.create(user),
                'list': CollectionPermission.list(user)
            },
            'subdivisions': {
                'add': SubdivisionPermission.create(user),
                'list': SubdivisionPermission.list(user)
            }
        }

    # TODO: If an organisation is associated to user and only when running
    # tests, organisation cannot not be encoded to JSON after call of
    # user.replace_refs() --> check why
    return jsonify(data)
Example #2
0
    def add_permissions(self, item):
        """Add permissions to record.

        :param item: Dict representing the record
        :returns: Dict of modified record.
        """
        item['permissions'] = {
            'read': DepositPermission.read(current_user, item),
            'update': DepositPermission.update(current_user, item),
            'delete': DepositPermission.delete(current_user, item)
        }

        return item
Example #3
0
def logged_user():
    """Current logged user informations in JSON."""
    if current_user.is_anonymous:
        return jsonify({})

    user = current_user_record

    if user and 'resolve' in request.args:
        user = user.replace_refs()

    data = {}

    if user:
        data['metadata'] = user.dumps()
        data['metadata']['is_superuser'] = user.is_superuser
        data['metadata']['is_admin'] = user.is_admin
        data['metadata']['is_moderator'] = user.is_moderator
        data['metadata']['is_submitter'] = user.is_submitter
        data['metadata']['is_user'] = user.is_user
        data['metadata']['permissions'] = {
            'users': {
                'add': UserPermission.create(user),
                'list': UserPermission.list(user)
            },
            'documents': {
                'add': DocumentPermission.create(user),
                'list': DocumentPermission.list(user)
            },
            'organisations': {
                'add': OrganisationPermission.create(user),
                'list': OrganisationPermission.list(user)
            },
            'deposits': {
                'add': DepositPermission.create(user),
                'list': DepositPermission.list(user)
            },
            'projects': {
                'add': ProjectPermission.create(user),
                'list': ProjectPermission.list(user)
            }
        }

    # TODO: If an organisation is associated to user and only when running
    # tests, organisation cannot not be encoded to JSON after call of
    # user.replace_refs() --> check why
    return jsonify(data)