(self, sketch_id)
return HTTP_STATUS_CODE_OK
Handles POST request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
Handles POST request to the resource.
Handles POST request to the resource .
def post(self, sketch_id):
        """Handles POST request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
        """
        sketch = Sketch.query.get_with_acl(sketch_id)
        if not sketch:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.')
        form = request.json

        if not sketch.has_permission(user=current_user, permission='write'):
            abort(
                HTTP_STATUS_CODE_FORBIDDEN,
                'The user does not have write permission on the sketch.')

        permission_string = form.get('permissions', '')
        if permission_string:
            try:
                permissions = json.loads(permission_string)
            except json.JSONDecodeError:
                permissions = []
        else:
            permissions = []

        # You cannot grant a permission you don't have.
        for permission in permissions:
            if not sketch.has_permission(
                    user=current_user, permission=permission):
                abort(
                    HTTP_STATUS_CODE_FORBIDDEN,
                    'The user does not have {0:s} permission on the sketch '
                    'and therefore can\'t grant it to '
                    'others'.format(permission))

        for username in form.get('users', []):
            # Try the username with any potential @domain preserved.
            user = User.query.filter_by(username=username).first()

            # If no hit, then try to strip the domain.
            if not user:
                base_username = username.split('@')[0]
                base_username = base_username.strip()
                user = User.query.filter_by(username=base_username).first()

            if user:
                user_permissions = permissions or ['read', 'write']
                for permission in user_permissions:
                    sketch.grant_permission(permission=permission, user=user)

        for group_name in form.get('groups', []):
            group = Group.query.filter_by(name=group_name).first()

            if not group:
                logger.error('Group: {0:s} not found'.format(group_name))
                continue

            # Only add groups publicly visible or owned by the current user
            if not group.user or group.user == current_user:
                group_permissions = permissions or ['read', 'write']
                for permission in group_permissions:
                    sketch.grant_permission(permission=permission, group=group)

        all_permissions = sketch.get_all_permissions()
        for username in form.get('remove_users', []):
            user = User.query.filter_by(username=username).first()
            permission_list = permissions or all_permissions.get(
                'user/{0:s}'.format(username), [])
            for permission in permission_list:
                sketch.revoke_permission(permission=permission, user=user)

        for group_name in form.get('remove_groups', []):
            group = Group.query.filter_by(name=group_name).first()
            permission_list = permissions or all_permissions.get(
                'group/{0:s}'.format(group_name), [])
            for permission in permission_list:
                sketch.revoke_permission(permission=permission, group=group)

        public = form.get('public')
        if public == 'true':
            sketch.grant_permission(permission='read')
        else:
            sketch.revoke_permission(permission='read')

        return HTTP_STATUS_CODE_OK
def post ( self , sketch_id ) : sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) form = request . json if not sketch . has_permission ( user = current_user , permission = 'write' ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'The user does not have write permission on the sketch.' ) permission_string = form . get ( 'permissions' , '' ) if permission_string : try : permissions = json . loads ( permission_string ) except json . JSONDecodeError : permissions = [ ] else : permissions = [ ] # You cannot grant a permission you don't have. for permission in permissions : if not sketch . has_permission ( user = current_user , permission = permission ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'The user does not have {0:s} permission on the sketch ' 'and therefore can\'t grant it to ' 'others' . format ( permission ) ) for username in form . get ( 'users' , [ ] ) : # Try the username with any potential @domain preserved. user = User . query . filter_by ( username = username ) . first ( ) # If no hit, then try to strip the domain. if not user : base_username = username . split ( '@' ) [ 0 ] base_username = base_username . strip ( ) user = User . query . filter_by ( username = base_username ) . first ( ) if user : user_permissions = permissions or [ 'read' , 'write' ] for permission in user_permissions : sketch . grant_permission ( permission = permission , user = user ) for group_name in form . get ( 'groups' , [ ] ) : group = Group . query . filter_by ( name = group_name ) . first ( ) if not group : logger . error ( 'Group: {0:s} not found' . format ( group_name ) ) continue # Only add groups publicly visible or owned by the current user if not group . user or group . user == current_user : group_permissions = permissions or [ 'read' , 'write' ] for permission in group_permissions : sketch . grant_permission ( permission = permission , group = group ) all_permissions = sketch . get_all_permissions ( ) for username in form . get ( 'remove_users' , [ ] ) : user = User . query . filter_by ( username = username ) . first ( ) permission_list = permissions or all_permissions . get ( 'user/{0:s}' . format ( username ) , [ ] ) for permission in permission_list : sketch . revoke_permission ( permission = permission , user = user ) for group_name in form . get ( 'remove_groups' , [ ] ) : group = Group . query . filter_by ( name = group_name ) . first ( ) permission_list = permissions or all_permissions . get ( 'group/{0:s}' . format ( group_name ) , [ ] ) for permission in permission_list : sketch . revoke_permission ( permission = permission , group = group ) public = form . get ( 'public' ) if public == 'true' : sketch . grant_permission ( permission = 'read' ) else : sketch . revoke_permission ( permission = 'read' ) return HTTP_STATUS_CODE_OK