Skip to content

Commit 2b78776

Browse files
committed
Don't let staff (or other non-passive branch members) subscribe as on of their passive branch memberships
1 parent 3ea2449 commit 2b78776

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/kotlin/be/sgl/backend/service/activity/CheckRegistrationStatusForUser.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package be.sgl.backend.service.activity
22

33
import be.sgl.backend.dto.ActivityRegistrationStatus
44
import be.sgl.backend.entity.branch.Branch
5+
import be.sgl.backend.entity.branch.BranchStatus
56
import be.sgl.backend.entity.registrable.activity.Activity
67
import be.sgl.backend.entity.registrable.activity.ActivityRestriction
78
import be.sgl.backend.entity.user.User
@@ -35,11 +36,16 @@ class CheckRegistrationStatusForUser {
3536
logger.info { "No active branch found for ${user.username}" }
3637
return ActivityRegistrationStatus(activeMembership = false)
3738
}
38-
val relevantRestrictions = activity.getRestrictionsForBranches(relevantBranches)
39+
var relevantRestrictions = activity.getRestrictionsForBranches(relevantBranches)
3940
if (relevantRestrictions.isEmpty()) {
4041
logger.info { "No applicable restrictions found for ${user.username}" }
4142
return ActivityRegistrationStatus()
4243
}
44+
val nonPassiveRelevantBranches = relevantBranches.filter { it.status != BranchStatus.PASSIVE }
45+
if (activity.getRestrictionsForBranches(nonPassiveRelevantBranches).isNotEmpty()) {
46+
logger.info { "Applicable non-passive branch restrictions found, prioritizing these" }
47+
relevantRestrictions = activity.getRestrictionsForBranches(nonPassiveRelevantBranches)
48+
}
4349
if (isGlobalLimitReached(activity)) {
4450
logger.info { "Global activity limit (${activity.registrationLimit}) is reached for ${activity.name}" }
4551
return ActivityRegistrationStatus(closedOptions = relevantRestrictions)

0 commit comments

Comments
 (0)