Example #1
0
    def _validate_permission(self, permission):
        """ Validate :permission: has allowed value.

        Valid permission is name of one of nefertari view methods or 'all'.
        :param permission: String representing ACL permission name.
        """
        valid_perms = set(self.PERMISSIONS.values())
        valid_perms.update(NEF_PERMISSIONS.values())
        if permission not in valid_perms:
            err = 'Invalid ACL permission value: {}. Valid values are: {}'
            raise ValueError(err.format(permission, ', '.join(valid_perms)))
Example #2
0
def validate_permissions(perms):
    """ Validate :perms: contains valid permissions.

    :param perms: List of permission names or ALL_PERMISSIONS.
    """
    if not isinstance(perms, (list, tuple)):
        perms = [perms]
    valid_perms = set(PERMISSIONS.values())
    if ALL_PERMISSIONS in perms:
        return perms
    if set(perms) - valid_perms:
        raise ValueError('Invalid ACL permission names. Valid permissions '
                         'are: {}'.format(', '.join(valid_perms)))
    return perms
Example #3
0
def validate_permissions(perms):
    """ Validate :perms: contains valid permissions.

    :param perms: List of permission names or ALL_PERMISSIONS.
    """
    if not isinstance(perms, (list, tuple)):
        perms = [perms]
    valid_perms = set(PERMISSIONS.values())
    if ALL_PERMISSIONS in perms:
        return perms
    if set(perms) - valid_perms:
        raise ValueError(
            'Invalid ACL permission names. Valid permissions '
            'are: {}'.format(', '.join(valid_perms)))
    return perms
Example #4
0
def parse_permissions(perms):
    """ Parse permissions ("perms") which are either exact permission
    names or the keyword 'all'.

    :param perms: List or comma-separated string of nefertari permission
        names, or 'all'
    """
    if isinstance(perms, six.string_types):
        perms = perms.split(',')
    perms = [perm.strip().lower() for perm in perms]
    if 'all' in perms:
        return ALL_PERMISSIONS
    else:
        valid_perms = set(PERMISSIONS.values())
        if set(perms) - valid_perms:
            raise ValueError(
                'Invalid ACL permission names. Valid permissions '
                'are: {}'.format(', '.join(valid_perms)))
        return perms