def join_group_request_impl(args): try: joiner = user_from_token(args['token']) group = group_from_id(int(args['group_id'])) is_blocked_from_group(joiner, group) user_can_join_group(joiner, group) group.subscriptions.append(joiner) if group.needs_approval_to_join is False: approve_subscription_of_user(joiner, group) db.session.commit() return Response(True, "Joined Group!", GroupSchema().dumps(group).data).output() except Exception as exception: return Response(False, str(exception), None).output()
def create_test_group_needing_approval(**kwargs): user = kwargs['user'] group = Group() group.active = True group.title = "Grupo" group.description = "Description" group.needs_approval_to_join = True group.admins.append(user) group.subscriptions.append(user) db.session.add(group) db.session.commit() approve_subscription_of_user(user,group) return group
def approve_join_request_impl(args): try: admin = user_from_token(args["token"]) user_pending = user_from_id(args["user_id"]) group = group_from_id(int(args["group_id"])) is_group_admin(admin, group) approved = bool(args["approved"]) if approved: approve_subscription_of_user(user_pending, group) else: remove_subscription_of_user(user_pending, group) db.session.commit() return Response( True, "Joined Group!" if approved is True else "Cannot Join Group!", GroupSchema().dumps(group).data ).output() except Exception as exception: return Response(False, str(exception), None).output()
def create_group_request_impl(args): new_group = Group() try: admin = user_from_token(args['token']) new_group.title = args['title'] new_group.description = args['description'] new_group.admins.append(admin) new_group.subscriptions.append(admin) new_group.needs_approval_to_join = bool(args['needs_approval']) db.session.add(new_group) db.session.commit() approve_subscription_of_user(admin, new_group) #add rules if args.has_key('rules') and args['rules'] is not None: for rule_dict in args['rules']: new_rule = Rule(rule_dict['property'], int(rule_dict['operand']), rule_dict['value'], rule_dict['value_type'], new_group) new_rule.name = rule_dict['name'] db.session.add(new_rule) new_group.rules.append(new_rule) db.session.commit() user_can_join_group(admin, new_group) #invite users if args.has_key('invited_user_ids') and args['invited_user_ids'] is not None: for invite_user_id in args['invited_user_ids']: args = {'token': admin.user_token.token, 'group_id': new_group.id, 'user_id': int(invite_user_id)} invite_request_impl(args) db.session.commit() return Response(True, "Group Created", GroupSchema().dumps(new_group).data).output() except Exception as exception: new_group.active = False return Response(False, str(exception), None).output()