Skip to content

Commit

Permalink
Add operation to un-deprecate an organisation (#4544)
Browse files Browse the repository at this point in the history
* Add operation to un-deprecate an organisation

* Remove println

* Add docs
  • Loading branch information
shinyhappydan authored Dec 1, 2023
1 parent e630da1 commit 55cb64d
Show file tree
Hide file tree
Showing 26 changed files with 493 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,58 @@ final class OrganizationsRoutes(
)
}
},
(resolveOrg & pathEndOrSingleSlash) { id =>
operationName(s"$prefixSegment/orgs/{label}") {
concat(
put {
parameter("rev".as[Int]) { rev =>
authorizeFor(id, orgs.write).apply {
// Update organization
entity(as[OrganizationInput]) { case OrganizationInput(description) =>
emitMetadata(
organizations
.update(id, description, rev)
)
resolveOrg { org =>
concat(
pathEndOrSingleSlash {
operationName(s"$prefixSegment/orgs/{label}") {
concat(
put {
parameter("rev".as[Int]) { rev =>
authorizeFor(org, orgs.write).apply {
// Update organization
entity(as[OrganizationInput]) { case OrganizationInput(description) =>
emitMetadata(
organizations
.update(org, description, rev)
)
}
}
}
}
}
},
get {
authorizeFor(id, orgs.read).apply {
parameter("rev".as[Int].?) {
case Some(rev) => // Fetch organization at specific revision
emit(organizations.fetchAt(id, rev).attemptNarrow[OrganizationRejection])
case None => // Fetch organization
emit(organizations.fetch(id).attemptNarrow[OrganizationRejection])
},
get {
authorizeFor(org, orgs.read).apply {
parameter("rev".as[Int].?) {
case Some(rev) => // Fetch organization at specific revision
emit(organizations.fetchAt(org, rev).attemptNarrow[OrganizationRejection])
case None => // Fetch organization
emit(organizations.fetch(org).attemptNarrow[OrganizationRejection])

}
}
},
// Deprecate or delete organization
delete {
parameters("rev".as[Int].?, "prune".as[Boolean].?) {
case (Some(rev), None) => deprecate(id, rev)
case (Some(rev), Some(false)) => deprecate(id, rev)
case (None, Some(true)) =>
authorizeFor(id, orgs.delete).apply {
emit(orgDeleter.delete(id).attemptNarrow[OrganizationRejection])
}
}
},
// Deprecate or delete organization
delete {
parameters("rev".as[Int].?, "prune".as[Boolean].?) {
case (Some(rev), None) => deprecate(org, rev)
case (Some(rev), Some(false)) => deprecate(org, rev)
case (None, Some(true)) =>
authorizeFor(org, orgs.delete).apply {
emit(orgDeleter.delete(org).attemptNarrow[OrganizationRejection])
}
case (_, _) => emit((InvalidDeleteRequest(org): OrganizationRejection).asLeft[Unit].pure[IO])
}
case (_, _) => emit((InvalidDeleteRequest(id): OrganizationRejection).asLeft[Unit].pure[IO])
}
)
}
},
(put & pathPrefix("undeprecate") & pathEndOrSingleSlash & parameter("rev".as[Int])) { rev =>
operationName(s"$prefixSegment/orgs/{label}/undeprecate") {
authorizeFor(org, orgs.write).apply {
emitMetadata(organizations.undeprecate(org, rev))
}
}
)
}
}
)
},
(label & pathEndOrSingleSlash) { label =>
operationName(s"$prefixSegment/orgs/{label}") {
Expand Down
Loading

0 comments on commit 55cb64d

Please sign in to comment.