Exemplo n.º 1
0
    def create_meeting(self,
                       title,
                       time=None,
                       location=None,
                       description=None):
        """See :http:post:`/api/meetings`."""
        if not self.user:
            raise PermissionError()

        e = InputError()
        if not str_or_none(title):
            e.errors['title'] = 'empty'
        e.trigger()

        meeting = Meeting(id='Meeting:' + randstr(),
                          trashed=False,
                          app=self,
                          authors=[self.user.id],
                          title=title,
                          time=time.isoformat() + 'Z' if time else None,
                          location=str_or_none(location),
                          description=str_or_none(description))
        self.r.oset(meeting.id, meeting)
        self.r.rpush('meetings', meeting.id)

        self.activity.publish(
            Event.create('create-meeting',
                         None, {'meeting': meeting},
                         app=self))
        return meeting
Exemplo n.º 2
0
    def post(self):
        if not self.app.user:
            raise micro.PermissionError()

        args = self.check_args({
            'type': str,
            'stack': str,
            'url': str,
            'message': (str, None, 'opt')
        })
        e = micro.InputError()
        if str_or_none(args['type']) is None:
            e.errors['type'] = 'empty'
        if str_or_none(args['stack']) is None:
            e.errors['stack'] = 'empty'
        if str_or_none(args['url']) is None:
            e.errors['url'] = 'empty'
        e.trigger()

        message = str_or_none(args.get('message'))
        message_part = ': ' + message if message else ''
        _LOGGER.error(
            _CLIENT_ERROR_LOG_TEMPLATE, args['type'], message_part, args['stack'].strip(),
            args['url'], self.app.user.name, self.app.user.id,
            self.request.headers.get('user-agent', '-'))
Exemplo n.º 3
0
    def do_edit(self, **attrs):
        e = InputError()
        if 'title' in attrs and str_or_none(attrs['title']) is None:
            e.errors['title'] = 'empty'
        if attrs.get('duration') is not None and attrs['duration'] <= 0:
            e.errors['duration'] = 'not_positive'
        e.trigger()

        if 'title' in attrs:
            self.title = attrs['title']
        if 'duration' in attrs:
            self.duration = attrs['duration']
        if 'description' in attrs:
            self.description = str_or_none(attrs['description'])
Exemplo n.º 4
0
    def do_edit(self, **attrs):
        e = InputError()
        if 'title' in attrs and not str_or_none(attrs['title']):
            e.errors['title'] = 'empty'
        e.trigger()

        if 'title' in attrs:
            self.title = attrs['title']
        if 'time' in attrs:
            self.time = attrs['time']
        if 'location' in attrs:
            self.location = str_or_none(attrs['location'])
        if 'description' in attrs:
            self.description = str_or_none(attrs['description'])
Exemplo n.º 5
0
    def do_edit(self, **attrs):
        e = InputError()
        if 'title' in attrs and str_or_none(attrs['title']) is None:
            e.errors['title'] = 'empty'
        if attrs.get('duration') is not None and attrs['duration'] <= 0:
            e.errors['duration'] = 'not_positive'
        e.trigger()

        if 'title' in attrs:
            self.title = attrs['title']
        if 'duration' in attrs:
            self.duration = attrs['duration']
        if 'description' in attrs:
            self.description = str_or_none(attrs['description'])
Exemplo n.º 6
0
    def do_edit(self, **attrs):
        e = InputError()
        if 'title' in attrs and not str_or_none(attrs['title']):
            e.errors['title'] = 'empty'
        e.trigger()

        if 'title' in attrs:
            self.title = attrs['title']
        if 'time' in attrs:
            self.time = attrs['time']
        if 'location' in attrs:
            self.location = str_or_none(attrs['location'])
        if 'description' in attrs:
            self.description = str_or_none(attrs['description'])
Exemplo n.º 7
0
    def create_meeting(self, title, time=None, location=None, description=None):
        """See :http:post:`/api/meetings`."""
        if not self.user:
            raise PermissionError()

        e = InputError()
        if not str_or_none(title):
            e.errors['title'] = 'empty'
        e.trigger()

        meeting = Meeting(
            id='Meeting:' + randstr(), trashed=False, app=self, authors=[self.user.id], title=title,
            time=time, location=str_or_none(location), description=str_or_none(description))
        self.r.oset(meeting.id, meeting)
        self.r.rpush('meetings', meeting.id)
        return meeting
Exemplo n.º 8
0
        async def _create(self,
                          title,
                          *,
                          text=None,
                          resource=None,
                          location=None):
            # pylint: disable=protected-access; List is a friend
            self.host[0]._check_permission(self.app.user, 'list-modify')
            attrs = await WithContent.process_attrs(
                {
                    'text': text,
                    'resource': resource
                }, app=self.app)
            if str_or_none(title) is None:
                raise micro.ValueError('title_empty')

            item = Item(id='Item:{}'.format(randstr()),
                        app=self.app,
                        authors=[self.app.user.id],
                        trashed=False,
                        text=attrs['text'],
                        resource=attrs['resource'],
                        list_id=self.host[0].id,
                        title=title,
                        location=location.json() if location else None,
                        checked=False)
            self.app.r.oset(item.id, item)
            self.app.r.rpush(self.map_key, item.id)
            self.host[0].activity.publish(
                Event.create('list-create-item', self.host[0], {'item': item},
                             self.app))
            return item
Exemplo n.º 9
0
    def do_edit(self, **attrs):
        if not self.app.user.id in self._staff:
            raise PermissionError()

        e = InputError()
        if 'title' in attrs and not str_or_none(attrs['title']):
            e.errors['title'] = 'empty'
        e.trigger()

        if 'title' in attrs:
            self.title = attrs['title']
        if 'icon' in attrs:
            self.icon = str_or_none(attrs['icon'])
        if 'favicon' in attrs:
            self.favicon = str_or_none(attrs['favicon'])
        if 'feedback_url' in attrs:
            self.feedback_url = str_or_none(attrs['feedback_url'])
Exemplo n.º 10
0
    def do_edit(self, **attrs):
        self._check_permission(self.app.user, 'list-modify')
        if 'title' in attrs and str_or_none(attrs['title']) is None:
            raise micro.ValueError('title_empty')
        if ('features' in attrs and
                not set(attrs['features']) <= {'check', 'assign', 'vote', 'location', 'play'}):
            raise micro.ValueError('feature_unknown')
        if 'mode' in attrs and attrs['mode'] not in {'collaborate', 'view'}:
            raise micro.ValueError('Unknown mode')

        if 'title' in attrs:
            self.title = attrs['title']
        if 'description' in attrs:
            self.description = str_or_none(attrs['description'])
        if 'features' in attrs:
            self.features = attrs['features']
        if 'mode' in attrs:
            self.mode = attrs['mode']
Exemplo n.º 11
0
    def create_agenda_item(self, title, duration=None, description=None):
        """See :http:post:`/api/meetings/(id)/items`."""
        if not self.app.user:
            raise PermissionError()

        e = InputError()
        if str_or_none(title) is None:
            e.errors['title'] = 'empty'
        if duration is not None and duration <= 0:
            e.errors['duration'] = 'not_positive'
        description = str_or_none(description)
        e.trigger()

        item = AgendaItem(
            id='AgendaItem:' + randstr(), trashed=False, app=self.app, authors=[self.app.user.id],
            title=title, duration=duration, description=description)
        self.app.r.oset(item.id, item)
        self.app.r.rpush(self._items_key, item.id)
        return item
Exemplo n.º 12
0
    def do_edit(self, **attrs):
        if self.app.user != self:
            raise PermissionError()

        e = InputError()
        if 'name' in attrs and not str_or_none(attrs['name']):
            e.errors['name'] = 'empty'
        e.trigger()

        if 'name' in attrs:
            self.name = attrs['name']
Exemplo n.º 13
0
    async def do_edit(self, **attrs):
        self._check_permission(self.app.user, 'item-modify')
        attrs = await WithContent.pre_edit(self, attrs)
        if 'title' in attrs and str_or_none(attrs['title']) is None:
            raise micro.ValueError('title_empty')

        WithContent.do_edit(self, **attrs)
        if 'title' in attrs:
            self.title = attrs['title']
        if 'location' in attrs:
            self.location = attrs['location']
Exemplo n.º 14
0
    def create_agenda_item(self, title, duration=None, description=None):
        """See :http:post:`/api/meetings/(id)/items`."""
        if not self.app.user:
            raise PermissionError()

        e = InputError()
        if str_or_none(title) is None:
            e.errors['title'] = 'empty'
        if duration is not None and duration <= 0:
            e.errors['duration'] = 'not_positive'
        description = str_or_none(description)
        e.trigger()

        item = AgendaItem(id='AgendaItem:' + randstr(),
                          trashed=False,
                          app=self.app,
                          authors=[self.app.user.id],
                          title=title,
                          duration=duration,
                          description=description)
        self.app.r.oset(item.id, item)
        self.app.r.rpush(self._items_key, item.id)
        return item