def kick(self, id): try: id = int(id) except (ValueError, TypeError): raise HTTPNotFound() room = DBSession.query(Room).filter(Room.id == id).one_or_none() if room is None: raise HTTPNotFound() member_id = context.form.get('memberId') member = DBSession.query(Member) \ .filter(Member.reference_id == member_id).one_or_none() if member is None: raise HTTPStatus('611 Member Not Found') is_member = DBSession.query(Member) \ .filter( TargetMember.target_id == id, TargetMember.member_id == member.id ) \ .count() if not is_member: raise HTTPStatus('617 Not A Member') DBSession.query(TargetMember) \ .filter( TargetMember.target_id == id, TargetMember.member_id == member.id ) \ .delete() return room
def get(self, id): try: id = int(id) except ValueError: raise HTTPNotFound() user = DBSession.query(Member).filter(Member.id == id).one_or_none() if user is None: raise HTTPNotFound() return user
def wrapper(*args, **kwargs): result = func(*args, **kwargs) if result is None: raise HTTPNotFound() if isinstance(result, Query): return cls.dump_query(result) return result
def get(self, id): id = int_or_notfound(id) card = DBSession.query(Card).get(id) if not member: raise HTTPNotFound() return card
def get(self, id): int_or_notfound(id) business = DBSession.query(Business), get(id) if business is None: HTTPNotFound() return business
def update(self, id): id = int_or_notfound(id) user_name = context.form.get('userName') email = context.form.get('email') member = DBSession.query(Member) \ .filter(Member.id == id) \ .one_or_none() if member is None: raise HTTPNotFound() username_exists = DBSession.query(Member) \ .filter(Member.user_name == user_name) \ .filter(Member.id != id) \ .one_or_none() if username_exists: raise StatusRepetitiveUsername() email_exist = DBSession.query(Member) \ .filter(Member.email == email) \ .filter(Member.id != id) \ .one_or_none() if email_exist: raise StatusRepetitiveEmail() member.update_from_request() return member
def check(self, subject): if subject == 'emails': return self.email_validation(context.form.get('email')) if subject == 'nicknames': return self.title_validation(context.form.get('title')) raise HTTPNotFound()
def see(self, id): id = int_or_notfound(id) member = Member.current() message = DBSession.query(Message).get(id) if message is None: raise HTTPNotFound() if message.sender_id == member.id: raise HTTPStatus('621 Can Not See Own Message') member_message_seen = DBSession.query(MemberMessageSeen) \ .filter(MemberMessageSeen.member_id == member.id) \ .filter(MemberMessageSeen.message_id == message.id) \ .one_or_none() if member_message_seen is not None: raise HTTPStatus('619 Message Already Seen') query = DBSession.query(Message) \ .filter(Message.target_id == message.target_id) \ .filter(Message.created_at <= message.created_at) \ .filter(Message.seen_at == None) \ .filter(Message.sender_id != member.id) \ query = Message.filter_by_request(query) for m in query: m.seen_by.append(member) seen_message = message.to_dict() seen_message.update({'type': 'seen'}) queues.push(settings.messaging.workers_queue, seen_message) return message
def get(self, id): id = int_or_notfound(id) member = DBSession.query(Member).get(id) if member is None: raise HTTPNotFound() return member
def unregister(self, id): id = int_or_notfound(id) member = DBSession.query(Member).get(id) if member is None: raise HTTPNotFound() DBSession.delete(member) return member
def __call__(self, *remaining_paths): calls = [story.base_call] + story.calls for call in calls: url = call.url.replace(':', '') if set(url.strip('/').split('/')) == set(remaining_paths): return self.server(call) raise HTTPNotFound()
def update(self, id): id = int_or_notfound(id) member = DBSession.query(Member).get(id) if member is None: raise HTTPNotFound() member.update_from_request() return member
def _get_member(self, id): id = int_or_notfound(id) member = DBSession.query(Member).filter(Member.id == id).one_or_none() if member is None: raise HTTPNotFound() return member
def get(self, title: str): person = DBSession.query(Person) \ .filter(Person.title == title) \ .one_or_none() if person is None: raise HTTPNotFound() return person
def get(self, id): foo = DBSession.query(Foo) \ .filter(Foo.id == id) \ .one_or_none() if foo is None: raise HTTPNotFound(f'Foo with id: {id} is not registered') return foo
def _get_target(self, id): try: int(id) except: raise HTTPStatus('706 Invalid Target Id') target = DBSession.query(Target).filter(Target.id == id).one_or_none() if target is None: raise HTTPNotFound('Target Not Exists') return target
def edit(self, id): foo = DBSession.query(Foo) \ .filter(Foo.id == id) \ .one_or_none() if foo is None: raise HTTPNotFound(f'Foo with id: {id} is not registered') foo.update_from_request() return foo
def delete(self, listtitle, itemtitle): me = context.identity.id item = DBSession.query(Item) \ .filter(Item.ownerid == me) \ .filter(Item.list == listtitle) \ .filter(Item.title == itemtitle) \ .one_or_none() if item is None: raise HTTPNotFound() DBSession.delete(item) return ''.join((str(item), CR))
def edit(self, id): id = int_or_notfound(id) new_message_body = context.form.get('body') message = DBSession.query(Message).get(id) if message is None: raise HTTPNotFound() if message.is_deleted: raise HTTPStatus('616 Message Already Deleted') if message.sender_id != Member.current().id: raise HTTPForbidden() message.body = new_message_body DBSession.add(message) DBSession.flush() queues.push(settings.messaging.workers_queue, message.to_dict()) return message
def reply(self, message_id): id = int_or_notfound(message_id) mimetype = context.form.get('mimetype') requested_message = DBSession.query(Message).get(id) if requested_message is None: raise HTTPNotFound() if requested_message.is_deleted: raise HTTPStatus('616 Message Already Deleted') message = Message( body=context.form.get('body'), target_id=requested_message.target_id, sender_id=Member.current().id, reply_to=requested_message, ) if 'attachment' in context.form: message.attachment = context.form.get('attachment') message.mimetype = message.attachment.content_type if message.attachment.content_type in BLACKLIST_MIME_TYPES: raise HTTPUnsupportedMediaType() elif mimetype: if mimetype not in SUPPORTED_TEXT_MIME_TYPES: raise HTTPUnsupportedMediaType() message.mimetype = mimetype else: message.mimetype = 'text/plain' DBSession.add(message) DBSession.flush() queues.push(settings.messaging.workers_queue, message.to_dict()) return message
def delete(self, id_: int = None): m = DBSession.query(Resource).filter(Resource.id == id_).one_or_none() if m is None: raise HTTPNotFound() DBSession.delete(m) return m
def put(self, id_: int = None): m = DBSession.query(Resource).filter(Resource.id == id_).one_or_none() if m is None: raise HTTPNotFound() m.update_from_request() return m
def mention(self): form = context.form mention = Mention() mention.body = form.get('body') origin_target = DBSession.query(Target) \ .filter(Target.id == form.get('originTargetId')) \ .one_or_none() if origin_target is None: raise HTTPTargetNotFound() mention.origin_target_id = origin_target.id if not (self.target or self.member): raise HTTPNotFound() if self.target: mention.target_id = self.target.id mention.sender_id = Member.current().id DBSession.add(mention) DBSession.flush() queues.push(settings.messaging.workers_queue, mention.to_dict()) else: mentioner = Member.current() mentioned = self.member if mentioner.id == mentioned.id: raise HTTPStatus('620 Can Not Mention Yourself') aliased_target = aliased(Target) aliased_target_member1 = aliased(TargetMember) aliased_target_member2 = aliased(TargetMember) target_member = DBSession.query(aliased_target_member1) \ .join( aliased_target_member2, aliased_target_member2.target_id == \ aliased_target_member1.target_id ) \ .filter(aliased_target_member2.member_id == mentioner.id) \ .filter(aliased_target_member1.member_id == mentioned.id) \ .join( aliased_target, aliased_target.id == aliased_target_member1.target_id ) \ .filter(aliased_target.type == 'direct') \ .one_or_none() mention.sender_id = mentioner.id if target_member is None: direct = Direct(members=[mentioner, mentioned]) DBSession.add(direct) DBSession.flush() mention.target_id = direct.id else: mention.target_id = target_member.target_id DBSession.add(mention) DBSession.flush() mention_message = mention.to_dict() mention_message.update({ 'mentionedMember': mentioned.id, 'type': 'mention' }) queues.push(settings.messaging.workers_queue, mention_message) webhook = Webhook() webhook.mentioned_member(mention.origin_target_id, mentioned.reference_id) return mention