コード例 #1
0
ファイル: service.py プロジェクト: wuchong718/dispatch
def create(*, db_session, project_in: ProjectCreate) -> Project:
    """Creates a project."""
    organization = organization_service.get_by_name(
        db_session=db_session, name=project_in.organization.name
    )
    project = Project(
        **project_in.dict(exclude={"organization"}),
        organization_id=organization.id,
    )

    db_session.add(project)
    db_session.commit()
    return project
コード例 #2
0
    def has_required_permissions(
        self,
        request: Request,
    ) -> bool:
        current_organization = organization_service.get_by_name(
            db_session=request.state.db,
            name=request.path_params["organization"])
        current_user = get_current_user(db_session=request.state.db,
                                        request=request)

        for org in current_user.organizations:
            if org.id == current_organization.id:
                if org.role == UserRoles.manager:
                    return True
コード例 #3
0
ファイル: service.py プロジェクト: Netflix/dispatch
def create_or_update_organization_role(*, db_session, user: DispatchUser,
                                       role_in: UserOrganization):
    """Creates a new organization role or updates an existing role."""
    if not role_in.organization.id:
        organization = organization_service.get_by_name(
            db_session=db_session, name=role_in.organization.name)
        organization_id = organization.id
    else:
        organization_id = role_in.organization.id

    organization_role = (db_session.query(DispatchUserOrganization).filter(
        DispatchUserOrganization.dispatch_user_id == user.id, ).filter(
            DispatchUserOrganization.organization_id ==
            organization_id).one_or_none())

    if not organization_role:
        return DispatchUserOrganization(
            organization_id=organization.id,
            role=role_in.role,
        )

    organization_role.role = role_in.role
    return organization_role