예제 #1
0
 def _create_grant(team_id, user_id, role='member'):
     with app.app_context():
         return GrantController.create({
             'team_id': team_id,
             'user_id': user_id,
             'role': role
         })
예제 #2
0
파일: teams.py 프로젝트: dingcycle/depc
    def put_grants(cls, team_id, grants):
        team = cls._get(filters={"Team": {"id": team_id}})

        for grant in grants:
            try:
                user_to_grant = UserController._get(
                    filters={"User": {
                        "name": grant["user"]
                    }})
            except NotFoundError:
                # Skip the unknown users and roles
                continue

            # Search a grant with this user and this team
            exist_grant = Grant.query.filter_by(team=team,
                                                user=user_to_grant).first()

            if not exist_grant:
                exist_grant = Grant(team=team, user=user_to_grant)
                db.session.add(exist_grant)

            # Change its role
            exist_grant.role = grant["role"]
            db.session.commit()

        return [GrantController.resource_to_dict(g) for g in team.grants]
예제 #3
0
    def get_grants(cls, team_id):
        team = cls._get(filters={"Team": {"id": team_id}})

        return [GrantController.resource_to_dict(g) for g in team.grants]