Example #1
0
 async def update_user_database(self, group: Group, user: User):
     user.group_name = group.name
     group.add_user(user.discord_id)
     logging.info(f"[CREATE GROUP - OK] User {user} en la base de datos")
     self.database.create_or_update_user(user)
     logging.info(f"[CREATE GROUP - OK] Creando grupo {group} en la base de datos")
     self.database.create_or_update_group(group)
Example #2
0
def add_group(args):
    group_id = Group.form_group_id(args['group_link'])
    group = Group.get_group(group_id)
    if group is not None:
        raise Error(StatusCode.BAD_REQUEST, 'Group is already existed')
    group = Group.add_group(group_id, args['group_name'])
    return jsonify({'status': True, 'group': group}), StatusCode.OK
Example #3
0
def delete_group(group_id):
    group = Group.get_group(group_id)
    if group is None:
        raise Error(StatusCode.NOT_FOUND, 'Cannot found group')
    Group.delete_group(group_id)
    return jsonify({
        'status': True,
        'message': 'Delete group successfully'
    }), StatusCode.OK
Example #4
0
def update_group(group_id, args):
    group = Group.get_group(group_id)
    if group is None:
        raise Error(StatusCode.NOT_FOUND, 'Cannot found group')
    if 'group_id' not in args:
        args['group_id'] = group['group_id']
    if 'group_name' not in args:
        args['group_name'] = group['group_name']
    new_group_id = args['group_id']
    group = Group.get_group(new_group_id)
    if new_group_id != group_id and group is not None:
        raise Error(StatusCode.BAD_REQUEST, 'Group ID is already existed')
    group = Group.update_group(group_id, new_group_id, args['group_name'])
    return jsonify({'status': True, 'group': group}), StatusCode.OK
Example #5
0
 def get_user_groups(cls, user_id):
     with get_db() as session:
         user_fb_link = cls.form_user_fb_link(user_id)
         return Group.serialize_groups(
             session.run(
                 "MATCH (n:User {userFBlink: $user_fb_link})-[:IS_MEMBER_OF]->(g:Group) RETURN g",
                 user_fb_link=user_fb_link).value())
 def get_group(self, group_name: str) -> Optional[Group]:
     todo_ref = self.db.collection(config['DISCORD_DB_PATH']  + '/groups')
     if group_name:
         doc = todo_ref.document(group_name.lower()).get()
         if doc.to_dict():
             return Group(doc.to_dict()['name'], doc.to_dict()['members'], doc.to_dict()['role_id'])
     return None
Example #7
0
 def recover_web_group_by_user(self, email):
     users_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/users')
     todo_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/teams')
     for grp in todo_ref.stream():
         members = grp.to_dict()['members']
         for member in members:
             user = users_ref.document(member.id).get().to_dict()
             if user['email'] == email:
                 return WebUser(user['accepted'], user['birthDate'], user['displayName'],
                            user['email'], user['fullName'], user['githubUrl'],
                            user['nickname']), Group(grp.to_dict()['name'])
     return self.recover_web_user(email), None
Example #8
0
def add_group(id):
    name = request.json["name"]
    description = request.json["description"]

    project = Project.query.filter_by(owner_id=current_user.id, id=id).first()
    if project is None:
        abort(401)

    new_group = Group(name, description, project.id)

    db.session.add(new_group)
    db.session.commit()

    return group_schema.jsonify(new_group)
 async def apply(self):
     msg = self.ctx.message.content.split()
     if len(msg) < 2:
         await self.ctx.send(texts.SINTAXIS_ERROR)
         return
     self.group_name = ' '.join(msg[1:])
     if self.group_exists():
         await self.ctx.send(texts.GROUP_ALREADY_EXISTS_ERROR)
         return
     await self.ctx.send(texts.STARTING_CREATE_GROUP)
     firebase_user = self.DB.get_user(discord_id=self.member.id)
     await self.group_creator.create_group(Group(name=self.group_name),
                                           self.member, firebase_user)
     await self.ctx.send(texts.CREATED_GROUP)
Example #10
0
def get_group_members(group_id):
    group = Group.get_group(group_id)
    if group is None:
        raise Error(StatusCode.NOT_FOUND, 'Cannot found group')
    members = Group.get_group_members(group_id)
    return jsonify({'status': True, 'members': members}), StatusCode.OK
Example #11
0
def get_groups():
    groups = Group.get_groups()
    return jsonify({'status': True, 'groups': groups}), StatusCode.OK
Example #12
0
 def recover_web_group(self, name) -> Union[Group, bool]:
     todo_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/teams')
     doc = todo_ref.document(name).get()
     return Group(doc.to_dict()['name']) if doc.to_dict() else None