예제 #1
0
파일: create.py 프로젝트: rafagonc/share
def create_rule_request_impl(args):
    try:
        user = user_from_token(args['token'])
        group = group_from_id(args['group_id'])
        is_group_admin(user, group)
        rule = Rule(args['property'], args['operand'] ,args['value'], args['value_type'], group)
        rule.name = args['name']
        db.session.add(rule)
        db.session.commit()
        return Response(True, "Rule Created" , RuleSchema().dumps(rule).data).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()
예제 #2
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()