-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c76c640
commit bab8a99
Showing
12 changed files
with
399 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/scala/org/broadinstitute/dsde/rawls/billing/BillingAdminService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.broadinstitute.dsde.rawls.billing | ||
|
||
import akka.http.scaladsl.model.StatusCodes | ||
import com.typesafe.scalalogging.LazyLogging | ||
import org.broadinstitute.dsde.rawls.RawlsExceptionWithErrorReport | ||
import org.broadinstitute.dsde.rawls.dataaccess.SamDAO | ||
import org.broadinstitute.dsde.rawls.model.{ | ||
BillingProjectAdminResponse, | ||
ErrorReport, | ||
RawlsBillingProjectName, | ||
RawlsRequestContext, | ||
SamResourceTypeAdminActions, | ||
SamResourceTypeNames | ||
} | ||
import org.broadinstitute.dsde.rawls.workspace.WorkspaceRepository | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class BillingAdminService(samDAO: SamDAO, | ||
billingRepository: BillingRepository, | ||
workspaceRepository: WorkspaceRepository, | ||
ctx: RawlsRequestContext | ||
)(implicit protected val ec: ExecutionContext) | ||
extends LazyLogging { | ||
|
||
def getBillingProjectSupportSummary( | ||
billingProjectName: RawlsBillingProjectName | ||
): Future[BillingProjectAdminResponse] = | ||
for { | ||
userIsAdmin <- samDAO.admin.userHasResourceTypeAdminPermission(SamResourceTypeNames.billingProject, | ||
SamResourceTypeAdminActions.readSummaryInformation, | ||
ctx | ||
) | ||
_ = if (!userIsAdmin) | ||
throw new RawlsExceptionWithErrorReport( | ||
ErrorReport(StatusCodes.Forbidden, "You must be an admin to call this API.") | ||
) | ||
|
||
billingProjectOpt <- billingRepository.getBillingProject(billingProjectName) | ||
billingProject = billingProjectOpt.getOrElse( | ||
throw new RawlsExceptionWithErrorReport( | ||
ErrorReport(StatusCodes.NotFound, s"Billing project ${billingProjectName.value} not found.") | ||
) | ||
) | ||
workspaces <- workspaceRepository.listWorkspacesByBillingProject(billingProjectName) | ||
} yield BillingProjectAdminResponse(billingProject, workspaces.map(ws => (ws.name, ws.workspaceIdAsUUID)).toMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.