-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIS-4747 - Add access requirements functionality (#72)
* APIS-4747 - Add Access Levels concept to model * APIS-4747 - Reduce size of potential json for now * APIS-4747 - Partial work * APIS-4747 - Fixed formatter * APIS-4747 - Remove commented code * APIS-4747 - Rename fieldsDefinition to apiFieldDefintions throughout * APIS-4747 - Renaming classes * APIS-4747 - Rename access level requirement entities to remove the word level * APIS-4747 - Remove unused value * APIS-4747 - Ensure invalid requirement combinations are prevented * APIS-4747 - Much improved data model
- Loading branch information
1 parent
249c30c
commit 9b42296
Showing
31 changed files
with
672 additions
and
363 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
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
70 changes: 70 additions & 0 deletions
70
app/uk/gov/hmrc/apisubscriptionfields/model/AccessRequirements.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,70 @@ | ||
/* | ||
* Copyright 2020 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.apisubscriptionfields.model | ||
|
||
sealed trait DevhubAccessRequirement | ||
object DevhubAccessRequirement { | ||
final val Default: DevhubAccessRequirement = Anyone | ||
|
||
case object NoOne extends DevhubAccessRequirement | ||
case object AdminOnly extends DevhubAccessRequirement | ||
case object Anyone extends DevhubAccessRequirement | ||
} | ||
|
||
case class DevhubAccessRequirements private ( | ||
val read: DevhubAccessRequirement, | ||
val write: DevhubAccessRequirement) { | ||
def satisfiesRead(dal: DevhubAccessLevel): Boolean = dal.satisfiesRequirement(read) // ReadWrite will be at least as strict. | ||
def satisfiesWrite(dal: DevhubAccessLevel): Boolean = dal.satisfiesRequirement(write) | ||
} | ||
|
||
|
||
object DevhubAccessRequirements { | ||
import DevhubAccessRequirement._ | ||
|
||
final val Default = new DevhubAccessRequirements(DevhubAccessRequirement.Default, DevhubAccessRequirement.Default) | ||
|
||
// Do not allow greater restrictions on read than on write | ||
// - it would make no sense to allow NoOne read but everyone write or developer write and admin read | ||
// | ||
def apply(read: DevhubAccessRequirement, write: DevhubAccessRequirement = DevhubAccessRequirement.Default): DevhubAccessRequirements = (read,write) match { | ||
case (NoOne, _) => new DevhubAccessRequirements(NoOne, NoOne) | ||
case (AdminOnly, Anyone) => new DevhubAccessRequirements(AdminOnly,AdminOnly) | ||
case _ => new DevhubAccessRequirements(read,write) | ||
} | ||
} | ||
|
||
case class AccessRequirements(devhub: DevhubAccessRequirements) | ||
object AccessRequirements { | ||
final val Default = AccessRequirements(devhub = DevhubAccessRequirements.Default) | ||
} | ||
|
||
|
||
sealed trait DevhubAccessLevel { | ||
def satisfiesRequirement(requirement: DevhubAccessRequirement): Boolean = DevhubAccessLevel.satisfies(requirement)(this) | ||
} | ||
object DevhubAccessLevel { | ||
case object Developer extends DevhubAccessLevel | ||
case object Admininstator extends DevhubAccessLevel | ||
|
||
import DevhubAccessRequirement._ | ||
def satisfies(requirement: DevhubAccessRequirement)(actual: DevhubAccessLevel): Boolean = (requirement, actual) match { | ||
case (NoOne, _) => false | ||
case (AdminOnly, Developer) => false | ||
case _ => true | ||
} | ||
} |
Oops, something went wrong.