Esempio n. 1
0
    def current_user_is_flamenco_manager(self) -> bool:
        """Returns True iff the user is a Flamenco Manager."""

        from pillar.api.utils.authorization import user_matches_roles

        return user_matches_roles({'service', 'flamenco_manager'},
                                  require_all=True)
Esempio n. 2
0
def assert_is_valid_patch(node_id, patch):
    """Raises an exception when the patch isn't valid."""

    try:
        op = patch['op']
    except KeyError:
        raise wz_exceptions.BadRequest("PATCH should have a key 'op' indicating the operation.")

    if op not in VALID_COMMENT_OPERATIONS:
        raise wz_exceptions.BadRequest('Operation should be one of %s',
                                       ', '.join(VALID_COMMENT_OPERATIONS))

    if op not in COMMENT_VOTING_OPS:
        # We can't check here, we need the node owner for that.
        return

    # See whether the user is allowed to patch
    if authorization.user_matches_roles(current_app.config['ROLES_FOR_COMMENT_VOTING']):
        log.debug('User is allowed to upvote/downvote comment')
        return

    # Access denied.
    log.info('User %s wants to PATCH comment node %s, but is not allowed.',
             authentication.current_user_id(), node_id)
    raise wz_exceptions.Forbidden()
Esempio n. 3
0
    def user_is_manager(self) -> bool:
        """Returns True iff the current user is a Flamenco manager service account."""

        from pillar.api.utils.authorization import user_matches_roles

        return user_matches_roles(
            require_roles={'service', 'flamenco_manager'}, require_all=True)
Esempio n. 4
0
def assert_file_size_allowed(file_size: int):
    """Asserts that the current user is allowed to upload a file of the given size.

    :raises wz_exceptions.RequestEntityTooLarge:
    """

    roles = current_app.config['ROLES_FOR_UNLIMITED_UPLOADS']
    if user_matches_roles(require_roles=roles):
        return

    filesize_limit = current_app.config['FILESIZE_LIMIT_BYTES_NONSUBS']
    if file_size < filesize_limit:
        return

    filesize_limit_mb = filesize_limit / 2.0**20
    log.info(
        'User %s tried to upload a %.3f MiB file, but is only allowed '
        '%.3f MiB.', current_user.user_id, file_size / 2.0**20,
        filesize_limit_mb)
    raise wz_exceptions.RequestEntityTooLarge(
        'To upload files larger than %i MiB, subscribe to Blender Cloud' %
        filesize_limit_mb)
Esempio n. 5
0
    def current_user_is_flamenco_manager(self) -> bool:
        """Returns True iff the user is a Flamenco Manager."""

        from pillar.api.utils.authorization import user_matches_roles

        return user_matches_roles({'service', 'flamenco_manager'}, require_all=True)