Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inversion of exclusion permissions and model validation #50

Merged
merged 3 commits into from
Jul 13, 2024

Conversation

ronenh
Copy link
Contributor

@ronenh ronenh commented Jul 13, 2024

This includes two bug fixes:

  1. Model validation wasn't checking for nil permission terms resulting in a panic instead of an error.
  2. During the inversion of exclusion permissions it is possible for the inverted relation to only have the 'include' term without the second 'exclude' term on certain types if objects of that type cannot have the excluded permission/relation to the object being inverted. In such cases the exclusion permission on those types becomes a single-term union.

For example, in this model fragment:

doc:
  relations:
    owner: user
    viewer: user | group#member
  permissions:
    can_act: viewer - owner

Only users can have the owner relation to a doc but either users or groups can have the viewer relation.
In the inverted model we expect to see:

user:
    relations:
        doc^owner: doc
        doc^viewer: doc
        group^member: group
    permissions:
        $doc^viewer: doc^viewer | $group^member->$doc^viewer#member
        $group^member: group^member | $group^member->$group^member#member

        # the inverted permission remain an exclusion permission
        doc^can_act: $doc^viewer - doc^owner

group:
    relations:
        doc^viewer#member: doc
        group^member#member: group
    permissions:
        $doc^viewer#member: doc^viewer#member | $group^member#member->$doc^viewer#member
        $group^member#member: group^member#member | $group^member#member->$group^member#member

        # the inverted permission becomes a union
        doc^can_act#member: $doc^viewer#member

@ronenh ronenh requested a review from gertd July 13, 2024 19:12
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9922251632

Details

  • 13 of 19 (68.42%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 60.894%

Changes Missing Coverage Covered Lines Changed/Added Lines %
model/types.go 1 3 33.33%
model/validate.go 1 5 20.0%
Totals Coverage Status
Change from base Build 9911233963: 0.03%
Covered Lines: 2806
Relevant Lines: 4608

💛 - Coveralls

@ronenh ronenh merged commit 2654cdd into main Jul 13, 2024
2 checks passed
@ronenh ronenh deleted the bugfix/negation-type-subset branch July 13, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants