Пример #1
0
 def unassign(self, assignee, *, user):
     """See :http:delete:`/api/lists/(list-id)/items/(id)/assignees/(assignee-id)`."""
     # pylint: disable=protected-access; Item is a friend
     self.item._check_permission(user, 'list-modify')
     if 'assign' not in self.item.list.features:
         raise error.ValueError('Disabled item list features assign')
     if self.item.trashed:
         raise error.ValueError('Trashed item')
     if not self.app.r.zrem(self.ids.key, assignee.id.encode()):
         raise error.ValueError(
             'No assignee {} in assignees of item {}'.format(assignee.id, self.item.id))
     self.item.list.activity.publish(
         Event.create('item-assignees-unassign', self.item, detail={'assignee': assignee},
                      app=self.app))
Пример #2
0
 def unvote(self, *, user):
     """See :http:delete:`/api/lists/(list-id)/items/(id)/votes/user`."""
     if not user:
         raise PermissionError()
     if 'vote' not in self.item.list.features:
         raise error.ValueError('Disabled item list features vote')
     if self.app.r.zrem(self.ids.key, user.id.encode()):
         self.item.list.activity.publish(
             Event.create('item-votes-unvote', self.item, app=self.app))
Пример #3
0
 def post(self, list_id, id):
     assignees = self.get_collection(list_id, id)
     try:
         assignee_id = self.get_arg('assignee_id', Expect.str)
         assignee = self.app.users[assignee_id]
     except KeyError:
         raise error.ValueError('No assignee {}'.format(assignee_id))
     assignees.assign(assignee, user=self.current_user)
     self.set_status(HTTPStatus.CREATED)
     self.write({})
Пример #4
0
        async def create(self, text: Optional[str], resource: Optional[str]) -> Greeting:
            """Create a :class:`Greeting` and return it."""
            user = context.user.get()
            if not user:
                raise error.PermissionError()
            attrs = await WithContent.process_attrs({'text': text, 'resource': resource},
                                                    app=self.app)
            if not (attrs['text'] or attrs['resource']):
                raise error.ValueError('No text and resource')

            greeting = Greeting(
                id='Greeting:{}'.format(randstr()), app=self.app, authors=[user.id],
                text=attrs['text'], resource=attrs['resource'])
            self.app.r.oset(greeting.id, greeting)
            self.app.r.lpush(self.ids.key, greeting.id)
            self.app.activity.publish(
                Event.create('greetings-create', None, detail={'greeting': greeting}, app=self.app))
            return greeting
Пример #5
0
 async def do_edit(self, **attrs):
     attrs = await WithContent.pre_edit(self, attrs)
     if not (attrs.get('text', self.text) or attrs.get('resource', self.resource)):
         raise error.ValueError('No text and resource')
     WithContent.do_edit(attrs)