Skip to content

Commit

Permalink
Creating new permission scope for working with reference solutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Oct 10, 2023
1 parent 315f551 commit c7f2542
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 21 deletions.
38 changes: 35 additions & 3 deletions app/V1Module/security/TokenScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,46 @@

use Nette\StaticClass;

/**
* Namespace for scope constants.
*/
class TokenScope
{
use StaticClass;

public const CHANGE_PASSWORD = "change-password";
/**
* The default scope with no additional restrictions.
*/
public const MASTER = "master";
public const EMAIL_VERIFICATION = "email-verification";
public const REFRESH = "refresh";

/**
* Read-only scope restricts operations to data retrieval only.
*/
public const READ_ALL = "read-all";

/**
* Used by 3rd party plagiarism detection tools to fetch solutions and feed similarities back.
*/
public const PLAGIARISM = "plagiarism";

/**
* Operations with reference solutions only. Can be used to insert additional solutions (e.g., created by GPT),
* as reference solutions to exercises.
*/
public const REF_SOLUTIONS = "ref-solutions";

/**
* Special scope used in password-retrieval links. The user can only change the local password.
*/
public const CHANGE_PASSWORD = "change-password";

/**
* Special scope used in password verification links. The user can only mark email address verified.
*/
public const EMAIL_VERIFICATION = "email-verification";

/**
* Usually used in combination with other scopes. Allows refreshing the token.
*/
public const REFRESH = "refresh";
}
105 changes: 87 additions & 18 deletions app/config/permissions.neon
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,21 @@ permissions:
- viewList
- viewAllTags

- allow: true
role: scope-ref-solutions
resource: exercise
actions:
- viewAll
- viewAllAuthors
- viewDetail
- viewConfig
- viewLimits
- viewScoreConfig
- viewAssignments
- viewList
- viewAllTags
- addReferenceSolution

- allow: true
role: student
resource: exercise
Expand Down Expand Up @@ -688,6 +703,59 @@ permissions:
conditions:
- exercise.isAuthorOrAdmin

- allow: true
role: supervisor-student
resource: exercise
actions:
- viewAll
- viewAllAuthors
- viewAllTags
- create # this is a generic rule (used to determine whether the user can be admin/author)

- allow: true
role: supervisor-student
resource: group
actions:
- createExercise # this is an explicit rule tested in creation endpoint (exercise is always created in a group)
conditions:
- group.isSupervisor
- group.isNotArchived

#######################
# Reference solutions #
#######################

- allow: true
role: scope-read-all
resource: referenceExerciseSolution
actions:
- viewDetail

- allow: true
role: scope-ref-solutions
resource: referenceExerciseSolution
actions:
- viewDetail
- promote

- allow: true
role: scope-ref-solutions
resource: referenceExerciseSolution
actions:
- evaluate
- deleteEvaluation
- setVisibility
- delete
conditions:
- referenceExerciseSolution.isExerciseNotArchived
- or:
- referenceExerciseSolution.isAuthor
- and:
- referenceExerciseSolution.isPublic
- or:
- referenceExerciseSolution.isExerciseAuthorOrAdmin
- referenceExerciseSolution.isExerciseSuperGroupAdmin

- allow: true
role: supervisor-student
resource: referenceExerciseSolution
Expand Down Expand Up @@ -730,24 +798,6 @@ permissions:
- referenceExerciseSolution.isExerciseNotArchived
- referenceExerciseSolution.isExerciseAuthorOrAdmin

- allow: true
role: supervisor-student
resource: exercise
actions:
- viewAll
- viewAllAuthors
- viewAllTags
- create # this is a generic rule (used to determine whether the user can be admin/author)

- allow: true
role: supervisor-student
resource: group
actions:
- createExercise # this is an explicit rule tested in creation endpoint (exercise is always created in a group)
conditions:
- group.isSupervisor
- group.isNotArchived

#############################
# Uploaded file permissions #
#############################
Expand All @@ -760,6 +810,25 @@ permissions:
- viewDetail
- downloadSupplementaryFile

- allow: true
role: scope-ref-solutions
resource: uploadedFile
actions:
- download
- viewDetail
- downloadSupplementaryFile
- upload

- allow: true
role: scope-ref-solutions
resource: uploadedPartialFile
actions:
- appendPartial
- cancelPartial
- completePartial
conditions:
- file.isStartedByCurrentUser

- allow: true
role: student
resource: uploadedFile
Expand Down

0 comments on commit c7f2542

Please sign in to comment.