コード例 #1
0
ファイル: create.py プロジェクト: rafagonc/share
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()
コード例 #2
0
ファイル: invite_tests.py プロジェクト: rafagonc/share
 def test_invite(self):
     response = invite_request_impl(self.args)
     assert response['success'] is True
     assert invite_from_id(response['data']['id']) in self.inviter.invitations_made
     assert invite_from_id(response['data']['id']) in self.invitee.invitations_recieved