Skip to content

Commit 9bcb51c

Browse files
committed
[ITB-2162] ANew community user permission to prevent organisation administrators from deleting obsolete test sessions
1 parent d61f817 commit 9bcb51c

19 files changed

Lines changed: 67 additions & 20 deletions

File tree

gitb-ui/app/controllers/CommunityService.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class CommunityService @Inject() (authorizedAction: AuthorizedAction,
155155
val allowCommunityView = requiredBodyParameter(request, ParameterNames.ALLOW_COMMUNITY_VIEW).toBoolean
156156
val allowUserManagement = requiredBodyParameter(request, ParameterNames.ALLOW_USER_MANAGEMENT).toBoolean
157157
val allowXmlReports = requiredBodyParameter(request, ParameterNames.ALLOW_XML_REPORTS).toBoolean
158+
val allowObsoleteSessionDeletion = requiredBodyParameter(request, ParameterNames.ALLOW_OBSOLETE_SESSION_DELETION).toBoolean
158159
val interactionNotification = requiredBodyParameter(request, ParameterNames.COMMUNITY_INTERACTION_NOTIFICATION).toBoolean
159160
var selfRegType: Short = SelfRegistrationType.NotSupported.id.toShort
160161
var selfRegRestriction: Short = SelfRegistrationRestriction.NoRestriction.id.toShort
@@ -213,7 +214,7 @@ class CommunityService @Inject() (authorizedAction: AuthorizedAction,
213214
interactionNotification, description, selfRegRestriction, selfRegForceTemplateSelection, selfRegForceRequiredProperties, selfRegAllowOrganisationTokens,
214215
selfRegAllowOrganisationTokenManagement, selfRegForceOrganisationTokenInput, selfRegJoinExisting, selfRegJoinJoinAsAdmin,
215216
allowCertificateDownload, allowStatementManagement, allowSystemManagement,
216-
allowPostTestOrganisationUpdate, allowPostTestSystemUpdate, allowPostTestStatementUpdate, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports,
217+
allowPostTestOrganisationUpdate, allowPostTestSystemUpdate, allowPostTestStatementUpdate, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports, allowObsoleteSessionDeletion,
217218
domainId, selfRegDefaultOrganisation, Some(ParameterExtractor.extractUserPreferenceDefaults(request)), forceUserPreferences, tags
218219
).map { _ =>
219220
ResponseConstructor.constructEmptyResponse

gitb-ui/app/controllers/util/ParameterExtractor.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ object ParameterExtractor {
418418
val allowCommunityView = requiredBodyParameter(request, ParameterNames.ALLOW_COMMUNITY_VIEW).toBoolean
419419
val allowUserManagement = requiredBodyParameter(request, ParameterNames.ALLOW_USER_MANAGEMENT).toBoolean
420420
val allowXmlReports = requiredBodyParameter(request, ParameterNames.ALLOW_XML_REPORTS).toBoolean
421+
val allowObsoleteSessionDeletion = requiredBodyParameter(request, ParameterNames.ALLOW_OBSOLETE_SESSION_DELETION).toBoolean
421422
val interactionNotification = requiredBodyParameter(request, ParameterNames.COMMUNITY_INTERACTION_NOTIFICATION).toBoolean
422423
var selfRegType: Short = SelfRegistrationType.NotSupported.id.toShort
423424
var selfRegRestriction: Short = SelfRegistrationRestriction.NoRestriction.id.toShort
@@ -475,7 +476,7 @@ object ParameterExtractor {
475476
selfRegRestriction, selfRegForceTemplateSelection, selfRegForceRequiredProperties, selfRegAllowOrganisationTokens, selfRegAllowOrganisationTokenManagement,
476477
selfRegForceOrganisationTokenInput, selfRegJoinExisting, selfRegJoinAsAdmin,
477478
allowCertificateDownload, allowStatementManagement, allowSystemManagement,
478-
allowPostTestOrganisationUpdate, allowPostTestSystemUpdate, allowPostTestStatementUpdate, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports,
479+
allowPostTestOrganisationUpdate, allowPostTestSystemUpdate, allowPostTestStatementUpdate, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports, allowObsoleteSessionDeletion,
479480
CryptoUtil.generateApiKey(), None, tags, domainId
480481
)
481482
}

gitb-ui/app/controllers/util/ParameterNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ object ParameterNames {
184184
val ALLOW_COMMUNITY_VIEW = "allow_community_view"
185185
val ALLOW_USER_MANAGEMENT = "allow_user_management"
186186
val ALLOW_XML_REPORTS = "allow_xml_reports"
187+
val ALLOW_OBSOLETE_SESSION_DELETION = "allow_obsolete_session_deletion"
187188
//TestService parameters
188189
val ACTOR_ID = "actor_id"
189190
val ACTOR_DEFAULT = "default"

gitb-ui/app/managers/AccountManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class AccountManager @Inject()(dbConfigProvider: DatabaseConfigProvider,
8686
selfRegForceOrganisationTokenInput = false, selfRegJoinExisting = false, selfRegJoinAsAdmin = true,
8787
allowCertificateDownload = false, allowStatementManagement = false, allowSystemManagement = false,
8888
allowPostTestOrganisationUpdates = false, allowPostTestSystemUpdates = false, allowPostTestStatementUpdates = false,
89-
allowAutomationApi = false, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true, "", None, None,
89+
allowAutomationApi = false, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true, allowObsoleteSessionDeletion = true, "", None, None,
9090
None)
9191
)).sorted
9292
}
@@ -124,7 +124,7 @@ class AccountManager @Inject()(dbConfigProvider: DatabaseConfigProvider,
124124
selfRegAllowOrganisationTokenManagement = false, selfRegForceOrganisationTokenInput = false, selfRegJoinExisting = false, selfRegJoinAsAdmin = true,
125125
allowCertificateDownload = false, allowStatementManagement = false, allowSystemManagement = false,
126126
allowPostTestOrganisationUpdates = false, allowPostTestSystemUpdates = false, allowPostTestStatementUpdates = false,
127-
allowAutomationApi = false, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true, "", None, None,
127+
allowAutomationApi = false, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true, allowObsoleteSessionDeletion = true, "", None, None,
128128
None))
129129
).sorted
130130
}

gitb-ui/app/managers/AuthorizationManager.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,24 @@ class AuthorizationManager @Inject()(dbConfigProvider: DatabaseConfigProvider,
19631963
}
19641964

19651965
def canDeleteObsoleteTestResultsForOrganisation(request: RequestWithAttributes[_], organisationId: Long): Future[Boolean] = {
1966-
canManageOrganisationBasic(request, organisationId)
1966+
val check = getUser(getRequestUserId(request)).flatMap { userInfo =>
1967+
if (isTestBedAdmin(userInfo)) {
1968+
Future.successful(true)
1969+
} else if (isCommunityAdmin(userInfo)) {
1970+
if (userInfo.organization.isDefined && userInfo.organization.get.id == organisationId) {
1971+
Future.successful(true)
1972+
} else {
1973+
organizationManager.getById(organisationId).map { org =>
1974+
org.isDefined && userInfo.organization.isDefined && org.get.community == userInfo.organization.get.community
1975+
}
1976+
}
1977+
} else {
1978+
communityManager.getById(userInfo.organization.get.community).map { community =>
1979+
isOrganisationAdmin(userInfo) && community.isDefined && community.get.allowObsoleteSessionDeletion && userInfo.organization.isDefined && userInfo.organization.get.id == organisationId
1980+
}
1981+
}
1982+
}
1983+
check.map(setAuthResult(request, _, "User cannot manage the requested organisation"))
19671984
}
19681985

19691986
def canDeleteTestResults(request: RequestWithAttributes[_], communityId: Option[Long]): Future[Boolean] = {

gitb-ui/app/managers/CommunityManager.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
403403
selfRegForceOrganisationTokenInput = false, selfRegJoinExisting = false, selfRegJoinAsAdmin = true,
404404
allowCertificateDownload = false, allowStatementManagement = true, allowSystemManagement = true, allowPostTestOrganisationUpdates = true,
405405
allowPostTestSystemUpdates = true, allowPostTestStatementUpdates = true,
406-
allowAutomationApi = true, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true,
406+
allowAutomationApi = true, allowCommunityView = false, allowUserManagement = true, allowXmlReports = true, allowObsoleteSessionDeletion = true,
407407
apiKeyToUse, None, None, domainId
408408
), None)
409409
}
@@ -534,7 +534,7 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
534534
description: Option[String], selfRegRestriction: Short, selfRegForceTemplateSelection: Boolean, selfRegForceRequiredProperties: Boolean,
535535
selfRegAllowOrganisationTokens: Boolean, selfRegAllowOrganisationTokenManagement: Boolean, selfRegForceOrganisationTokenInput: Boolean,
536536
selfRegJoinExisting: Boolean, selfRegJoinAsAdmin: Boolean, allowCertificateDownload: Boolean, allowStatementManagement: Boolean, allowSystemManagement: Boolean,
537-
allowPostTestOrganisationUpdates: Boolean, allowPostTestSystemUpdates: Boolean, allowPostTestStatementUpdates: Boolean, allowAutomationApi: Option[Boolean], allowCommunityView: Boolean, allowUserManagement: Boolean, allowXmlReports: Boolean,
537+
allowPostTestOrganisationUpdates: Boolean, allowPostTestSystemUpdates: Boolean, allowPostTestStatementUpdates: Boolean, allowAutomationApi: Option[Boolean], allowCommunityView: Boolean, allowUserManagement: Boolean, allowXmlReports: Boolean, allowObsoleteSessionDeletion: Boolean,
538538
apiKey: Option[String], domainId: Option[Long], checkApiKeyUniqueness: Boolean, userPreferences: Option[UserPreferenceDefaults], overrideExistingUserPreferences: Boolean, tags: Option[String], onSuccess: mutable.ListBuffer[() => _]) = {
539539
for {
540540
// Update short name.
@@ -564,11 +564,11 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
564564
.map(c => (
565565
c.supportEmail, c.domain, c.description, c.allowCertificateDownload, c.allowStatementManagement, c.allowSystemManagement,
566566
c.allowPostTestOrganisationUpdates, c.allowPostTestSystemUpdates, c.allowPostTestStatementUpdates, c.allowCommunityView,
567-
c.allowUserManagement, c.allowXmlReports, c.interactionNotification, c.tags
567+
c.allowUserManagement, c.allowXmlReports, c.allowObsoleteSessionDeletion, c.interactionNotification, c.tags
568568
))
569569
.update(supportEmail, domainId, description, allowCertificateDownload, allowStatementManagement, allowSystemManagement,
570570
allowPostTestOrganisationUpdates, allowPostTestSystemUpdates, allowPostTestStatementUpdates, allowCommunityView,
571-
allowUserManagement, allowXmlReports, interactionNotification, tags
571+
allowUserManagement, allowXmlReports, allowObsoleteSessionDeletion, interactionNotification, tags
572572
)
573573
// Update user preferences.
574574
_ <- {
@@ -699,7 +699,7 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
699699
community.selfRegJoinExisting, community.selfRegJoinAsAdmin,
700700
community.allowCertificateDownload, community.allowStatementManagement, community.allowSystemManagement,
701701
community.allowPostTestOrganisationUpdates, community.allowPostTestSystemUpdates, community.allowPostTestStatementUpdates,
702-
Some(community.allowAutomationApi), community.allowCommunityView, community.allowUserManagement, community.allowXmlReports, None, domainIdToUse,
702+
Some(community.allowAutomationApi), community.allowCommunityView, community.allowUserManagement, community.allowXmlReports, community.allowObsoleteSessionDeletion, None, domainIdToUse,
703703
checkApiKeyUniqueness = false, None, overrideExistingUserPreferences = false, community.tags, onSuccess
704704
)
705705
}
@@ -718,7 +718,7 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
718718
selfRegForceOrganisationTokenInput: Boolean, selfRegJoinExisting: Boolean, selfRegJoinAsAdmin: Boolean,
719719
allowCertificateDownload: Boolean, allowStatementManagement: Boolean, allowSystemManagement: Boolean,
720720
allowPostTestOrganisationUpdates: Boolean, allowPostTestSystemUpdates: Boolean,
721-
allowPostTestStatementUpdates: Boolean, allowAutomationApi: Option[Boolean], allowCommunityView: Boolean, allowUserManagement: Boolean, allowXmlReports: Boolean,
721+
allowPostTestStatementUpdates: Boolean, allowAutomationApi: Option[Boolean], allowCommunityView: Boolean, allowUserManagement: Boolean, allowXmlReports: Boolean, allowObsoleteSessionDeletion: Boolean,
722722
domainId: Option[Long], selfRegDefaultOrganisation: Option[Long], userPreferences: Option[UserPreferenceDefaults], overrideExistingUserPreferences: Boolean,
723723
tags: Option[String]): Future[Unit] = {
724724

@@ -732,7 +732,7 @@ class CommunityManager @Inject() (repositoryUtils: RepositoryUtils,
732732
selfRegNotification, interactionNotification, description, selfRegRestriction, selfRegForceTemplateSelection, selfRegForceRequiredProperties,
733733
selfRegAllowOrganisationTokens, selfRegAllowOrganisationTokenManagement, selfRegForceOrganisationTokenInput, selfRegJoinExisting, selfRegJoinAsAdmin,
734734
allowCertificateDownload, allowStatementManagement, allowSystemManagement,
735-
allowPostTestOrganisationUpdates, allowPostTestSystemUpdates, allowPostTestStatementUpdates, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports,
735+
allowPostTestOrganisationUpdates, allowPostTestSystemUpdates, allowPostTestStatementUpdates, allowAutomationApi, allowCommunityView, allowUserManagement, allowXmlReports, allowObsoleteSessionDeletion,
736736
None, domainId, checkApiKeyUniqueness = false, userPreferences, overrideExistingUserPreferences, tags, onSuccess
737737
)
738738
} else {

gitb-ui/app/managers/export/ExportManager.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ class ExportManager @Inject() (repositoryUtils: RepositoryUtils,
13241324
communityData.setAllowCommunityView(community.get.allowCommunityView)
13251325
communityData.setAllowUserManagement(community.get.allowUserManagement)
13261326
communityData.setAllowXmlReports(community.get.allowXmlReports)
1327+
communityData.setAllowObsoleteSessionDeletion(community.get.allowObsoleteSessionDeletion)
13271328
communityData.setInteractionNotification(community.get.interactionNotification)
13281329
// User preference defaults.
13291330
communityData.setDefaultUserPreferences(new com.gitb.xml.export.UserPreferences)

gitb-ui/app/managers/export/ImportCompleteManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ class ImportCompleteManager @Inject()(systemConfigurationManager: SystemConfigur
24432443
data.getSelfRegistrationSettings.isForceTemplateSelection, data.getSelfRegistrationSettings.isForceRequiredProperties, data.getSelfRegistrationSettings.isAllowOrganisationTokens, data.getSelfRegistrationSettings.isAllowOrganisationTokenManagement,
24442444
data.getSelfRegistrationSettings.isForceOrganisationTokenInput, data.getSelfRegistrationSettings.isJoinExisting, data.getSelfRegistrationSettings.isJoinAsAdmin,
24452445
data.isAllowCertificateDownload, data.isAllowStatementManagement, data.isAllowSystemManagement,
2446-
data.isAllowPostTestOrganisationUpdates, data.isAllowSystemManagement, data.isAllowPostTestStatementUpdates, data.isAllowAutomationApi, data.isAllowCommunityView, data.isAllowUserManagement, data.isAllowXmlReports,
2446+
data.isAllowPostTestOrganisationUpdates, data.isAllowSystemManagement, data.isAllowPostTestStatementUpdates, data.isAllowAutomationApi, data.isAllowCommunityView, data.isAllowUserManagement, data.isAllowXmlReports, data.isAllowObsoleteSessionDeletion,
24472447
apiKey, None, Option(data.getTags), domainId
24482448
), checkApiKeyUniqueness = true, toModelUserPreferenceDefaults(data, 0L))
24492449
},
@@ -2456,7 +2456,7 @@ class ImportCompleteManager @Inject()(systemConfigurationManager: SystemConfigur
24562456
data.getSelfRegistrationSettings.isForceTemplateSelection, data.getSelfRegistrationSettings.isForceRequiredProperties, data.getSelfRegistrationSettings.isAllowOrganisationTokens, data.getSelfRegistrationSettings.isAllowOrganisationTokenManagement,
24572457
data.getSelfRegistrationSettings.isForceOrganisationTokenInput, data.getSelfRegistrationSettings.isJoinExisting, data.getSelfRegistrationSettings.isJoinAsAdmin,
24582458
data.isAllowCertificateDownload, data.isAllowStatementManagement, data.isAllowSystemManagement,
2459-
data.isAllowPostTestOrganisationUpdates, data.isAllowSystemManagement, data.isAllowPostTestStatementUpdates, Some(data.isAllowAutomationApi), data.isAllowCommunityView, data.isAllowUserManagement, data.isAllowXmlReports,
2459+
data.isAllowPostTestOrganisationUpdates, data.isAllowSystemManagement, data.isAllowPostTestStatementUpdates, Some(data.isAllowAutomationApi), data.isAllowCommunityView, data.isAllowUserManagement, data.isAllowXmlReports, data.isAllowObsoleteSessionDeletion,
24602460
Some(apiKey), domainId, checkApiKeyUniqueness = true, toModelUserPreferenceDefaults(data, targetCommunity.get.id), overrideExistingUserPreferences = false, Option(data.getTags), ctx.onSuccessCalls
24612461
)
24622462
},

gitb-ui/app/models/Community.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ case class Communities(
4444
allowCommunityView : Boolean,
4545
allowUserManagement: Boolean,
4646
allowXmlReports: Boolean,
47+
allowObsoleteSessionDeletion: Boolean,
4748
apiKey: String,
4849
latestStatusLabel: Option[String],
4950
tags: Option[String],
@@ -84,6 +85,7 @@ class Community(
8485
_allowCommunityView: Boolean,
8586
_allowUserManagement: Boolean,
8687
_allowXmlReports: Boolean,
88+
_allowObsoleteSessionDeletion: Boolean,
8789
_apiKey: String,
8890
_domain:Option[Domain],
8991
_defaultSelfRegOrganisation: Option[Organizations],
@@ -117,6 +119,7 @@ class Community(
117119
var allowCommunityView: Boolean = _allowCommunityView
118120
var allowUserManagement: Boolean = _allowUserManagement
119121
var allowXmlReports: Boolean = _allowXmlReports
122+
var allowObsoleteSessionDeletion: Boolean = _allowObsoleteSessionDeletion
120123
var apiKey: String = _apiKey
121124
var domain:Option[Domain] = _domain
122125
var defaultSelfRegOrganisation: Option[Organizations] = _defaultSelfRegOrganisation
@@ -153,6 +156,7 @@ class Community(
153156
_case.allowCommunityView,
154157
_case.allowUserManagement,
155158
_case.allowXmlReports,
159+
_case.allowObsoleteSessionDeletion,
156160
_case.apiKey,
157161
_domain,
158162
_defaultSelfRegOrganisation,
@@ -197,6 +201,7 @@ class Community(
197201
allowCommunityView,
198202
allowUserManagement,
199203
allowXmlReports,
204+
allowObsoleteSessionDeletion,
200205
apiKey,
201206
None,
202207
tags,

0 commit comments

Comments
 (0)