Skip to content

Commit

Permalink
ID-813 Add TOS rolling acceptance window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-in-a-Jar committed Oct 13, 2023
1 parent 4b07b8e commit 64f8223
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.broadinstitute.dsde.workbench.sam.config.GoogleServicesConfig.googleS
import org.broadinstitute.dsde.workbench.sam.dataAccess.DistributedLockConfig
import org.broadinstitute.dsde.workbench.sam.model._

import java.time.Instant
import scala.concurrent.duration.Duration

/** Created by dvoet on 7/18/17.
Expand Down Expand Up @@ -119,7 +120,9 @@ object AppConfig {
config.getAs[Boolean]("isTosEnabled").getOrElse(true),
config.getBoolean("isGracePeriodEnabled"),
config.getString("version"),
config.getString("baseUrl")
config.getString("baseUrl"),
// Must be a valid UTC datetime string in ISO 8601 format ex: 2007-12-03T10:15:30.00Z
Instant.parse(config.getString("rollingAcceptanceWindowExpirationDatetime"))
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.broadinstitute.dsde.workbench.sam.config

import java.time.Instant

/** Terms of Service configuration.
* @param isGracePeriodEnabled
* Set to true if the grace period for ToS acceptance is active
* @param version
* The latest version of the Terms of Service
* @param url
* @param baseUrl
* The url to the Terra Terms of Service. Used for validation and will be displayed to user in error messages
* @param rollingAcceptanceWindowExpiration
* The expiration time for the rolling acceptance window. If the user has not accepted the new ToS by this time,
* they will be denied access to the system. Must be a valid UTC datetime string in ISO 8601 format
* example: 2007-12-03T10:15:30.00Z
*/

case class TermsOfServiceConfig(isTosEnabled: Boolean, isGracePeriodEnabled: Boolean, version: String, baseUrl: String)
case class TermsOfServiceConfig(isTosEnabled: Boolean, isGracePeriodEnabled: Boolean, version: String, baseUrl: String, rollingAcceptanceWindowExpiration: Instant)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.io.{FileNotFoundException, IOException}
import scala.concurrent.{Await, ExecutionContext}
import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
import java.time.Instant
import scala.io.Source

class TosService(val directoryDao: DirectoryDAO, val tosConfig: TermsOfServiceConfig)(
Expand Down Expand Up @@ -60,13 +61,15 @@ class TosService(val directoryDao: DirectoryDAO, val tosConfig: TermsOfServiceCo
/** If grace period enabled, don't check ToS, return true If ToS disabled, return true Otherwise return true if user has accepted ToS, or is a service account
*/
private def tosAcceptancePermitsSystemUsage(user: SamUser, userTos: Option[SamUserTos]): Boolean = {
val now = Instant.now()
val userIsServiceAccount = StandardSamUserDirectives.SAdomain.matches(user.email.value) // Service Account users do not need to accept ToS
val userIsPermitted = userTos.exists { tos =>
val userHasAcceptedLatestVersion = userHasAcceptedLatestTosVersion(Option(tos))
val userCanUseSystemUnderGracePeriod = tosConfig.isGracePeriodEnabled && tos.action == TosTable.ACCEPT
val tosDisabled = !tosConfig.isTosEnabled
val userInsideOfRollingAcceptanceWindow = tosConfig.rollingAcceptanceWindowExpiration.isAfter(now)

userHasAcceptedLatestVersion || userCanUseSystemUnderGracePeriod || tosDisabled
userHasAcceptedLatestVersion || userInsideOfRollingAcceptanceWindow || userCanUseSystemUnderGracePeriod || tosDisabled

}
userIsPermitted || userIsServiceAccount
Expand Down

0 comments on commit 64f8223

Please sign in to comment.