Example #1
0
    def put(self):
        """
        Processes put requests
        """
        logger.debug('Put args: {}'.format(self._args))

        la = len(self._args)

        if la == 5 and self._args[3] == 'add':
            perm = {
                '0': permissions.PERMISSION_NONE,
                '1': permissions.PERMISSION_READ,
                '2': permissions.PERMISSION_MANAGEMENT,
                '3': permissions.PERMISSION_ALL
            }.get(self._params.get('perm', '0'), permissions.PERMISSION_NONE)

            cls = Permissions.getClass(self._args[0])

            obj = cls.objects.get(uuid=self._args[1])

            if self._args[2] == 'users':
                user = User.objects.get(uuid=self._args[4])
                permissions.addUserPermission(user, obj, perm)
            elif self._args[2] == 'groups':
                group = Group.objects.get(uuid=self._args[4])
                permissions.addGroupPermission(group, obj, perm)
            else:
                raise RequestError('Ivalid request')

            return Permissions.permsToDict(permissions.getPermissions(obj))
        elif la == 1 and self._args[0] == 'revoke':
            items = self._params.get('items', [])
            for permId in items:
                permissions.revokePermissionById(permId)
            return {}
        else:
            raise RequestError('Invalid request')
Example #2
0
    def put(self):
        '''
        Processes post requests
        '''
        logger.debug('Put args: {}'.format(self._args))

        la = len(self._args)

        if la == 5 and self._args[3] == 'add':
            perm = {
                '0': permissions.PERMISSION_NONE,
                '1': permissions.PERMISSION_READ,
                '2': permissions.PERMISSION_MANAGEMENT,
                '3': permissions.PERMISSION_ALL
            }.get(self._params.get('perm', '0'), permissions.PERMISSION_NONE)

            cls = Permissions.getClass(self._args[0])

            obj = cls.objects.get(uuid=self._args[1])

            if self._args[2] == 'users':
                user = User.objects.get(uuid=self._args[4])
                permissions.addUserPermission(user, obj, perm)
            elif self._args[2] == 'groups':
                group = Group.objects.get(uuid=self._args[4])
                permissions.addGroupPermission(group, obj, perm)
            else:
                raise RequestError('Ivalid request')

            return Permissions.permsToDict(permissions.getPermissions(obj))
        elif la == 1 and self._args[0] == 'revoke':
            items = self._params.get('items', [])
            for permId in items:
                permissions.revokePermissionById(permId)
            return {}
        else:
            raise RequestError('Invalid request')