예제 #1
0
파일: teams.py 프로젝트: cahna/yaits
def create_team() -> Response:
    user_uuid = get_jwt_identity().get('unique_id')
    user = users.get_user_by_id(user_uuid)
    data = team_schema.load(request.get_json())
    team = teams.create_team(data.get('name'), user)

    return team_schema.jsonify(team)
예제 #2
0
def update_issue(issue: Issue, updates: Mapping):
    if updates.get('status_unique_id'):
        status_uuid = updates.get('status_unique_id')
        status = get_issue_status_by_uuid(status_uuid)

        if status.team.slug != issue.team.slug:
            raise UpdateIssueBadRequest()

        issue.status_id = status.id

    if updates.get('assigned_to_unique_id'):
        assigned_uuid = updates.get('assigned_to_unique_id')
        assignee = get_user_by_id(assigned_uuid)

        if issue.team.slug not in [t.slug for t in assignee.teams]:
            raise UpdateIssueBadRequest()

        issue.assigned_to_id = assignee.id

    if updates.get('description'):
        issue.description = updates.get('description')

    if updates.get('short_description'):
        issue.short_description = updates.get('short_description')

    if updates.get('priority'):
        issue.priority = updates.get('priority')

    db.session.commit()
예제 #3
0
def create_issue(short_description: str,
                 description: str,
                 status_unique_id: str,
                 team: Team,
                 created_by: User,
                 assigned_to_uuid: str = None,
                 priority: int = 0) -> Issue:
    status = get_issue_status_by_uuid(status_unique_id)

    if not status:
        raise CreateIssueUnprocessable('No such status')

    if status.team_id != team.id:
        raise CreateIssueUnprocessable('Invalid status')

    assigned_to_user = created_by

    if assigned_to_uuid:
        assigned_to_user = get_user_by_id(assigned_to_uuid)

    issue = Issue(short_description=short_description,
                  description=description,
                  status_id=status.id,
                  team_id=team.id,
                  created_by_id=created_by.id,
                  assigned_to_id=assigned_to_user.id,
                  priority=priority)

    db.session.add(issue)
    db.session.commit()

    return issue
예제 #4
0
def verify_user_in_team(team_slug: str, user_uuid: str) -> List:
    """If valid, return [Team, User]
    TODO: Refactor into Flask route decorator(?)
    """
    team = get_team_by_slug(team_slug)
    user = get_user_by_id(user_uuid)

    if team_slug not in [t.slug for t in user.teams]:
        raise ActionForbidden()

    return team, user
예제 #5
0
 def resolve_user(root, info, id):
     return get_user_by_id(id)
예제 #6
0
 def get_node(parent, info, id):
     return get_user_by_id(id)
예제 #7
0
def get_active_user() -> Response:
    identity = get_jwt_identity()
    user = get_user_by_id(identity['unique_id'])

    return user_schema.jsonify(user)
예제 #8
0
파일: flask.py 프로젝트: cahna/yaits
 def resolve(self, next, root, info, **kwargs):
     identity = get_jwt_identity()
     user = get_user_by_id(identity['unique_id'])
     info.context.yaits_user = user
     return next(root, info, **kwargs)