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

Get permission service: clean "can_request_help" usage #1006

Merged
merged 18 commits into from
Sep 13, 2023
Merged

Conversation

GeoffreyHuck
Copy link
Contributor

@GeoffreyHuck GeoffreyHuck commented Sep 8, 2023

fixes #1004

We now return an array of all groups with can_request_help_to permissions set in all granted_via_*.

In computed, we also return all permissions coming from parent items while request_help_propagation is set. The uses a recursive query that is only called once, GetAncestorsRequestHelpPropagatedQuery().

Format of can_request_help_to in response

  • id always set
  • name present only if it is visible
  • is_all_users_group to true or false depending on the case

Performance notice:

  • We use the query IsVisibleForGroup() once for each group we find. So it might be expensive if we have cases where we have many groups can_request_help_to permissions set.

The typical query is the following:

SELECT 1 FROM `groups` 
WHERE (groups.is_public OR groups.id IN(
    SELECT groups_ancestors_active.ancestor_group_id
    FROM `groups_groups_active`
    JOIN groups_ancestors_active ON groups_ancestors_active.child_group_id = groups_groups_active.parent_group_id
    JOIN `groups` AS ancestor_group ON ancestor_group.id = groups_ancestors_active.ancestor_group_id
    WHERE (groups_groups_active.child_group_id = 5549855599337303585)
    AND (ancestor_group.type != 'ContestParticipants'
))
OR groups.id IN(
    SELECT ancestors_of_managed.ancestor_group_id FROM `groups_ancestors_active` 
    JOIN group_managers ON group_managers.group_id = `groups_ancestors_active`.ancestor_group_id 
    JOIN groups_ancestors_active AS group_ancestors ON group_ancestors.ancestor_group_id = group_managers.manager_id
        AND group_ancestors.child_group_id = 5549855599337303585
    JOIN `groups` ON groups.id = groups_ancestors_active.child_group_id 
    JOIN groups_ancestors_active AS ancestors_of_managed ON ancestors_of_managed.child_group_id = groups_ancestors_active.child_group_id
        AND (groups.type != 'User' OR ancestors_of_managed.is_self)
    JOIN `groups` AS ancestor_group ON ancestor_group.id = ancestors_of_managed.ancestor_group_id
    WHERE (ancestor_group.type != 'ContestParticipants')
))
AND (groups.id = 2646504854435585587)
LIMIT 1

Note: It might be easier to review commit by commit. Notes about choices are present in commit messages.

… granted_via_*

For now, it is always an empty array
We need it to test the viewPermissions service
…abase if it doesn't exists

It seems obvious but it wasn't the case because database foreign keys are disabled in tests
Because we have cases that weren't covered to test for the viewPermissions service changes
Note: we don't distinguish between empty string and nil. It doesn't seem important now, but it might be a requirement in the future.
…s for group_membership, item_unlocking, self and other

Also changed the structure of a can_request_help_to permission: id, is_all_users_group and name are now always present. It improves consistency.
Not implemented for computed yet
@see #1004
…_request_help_to

Note: it doesn't contain the groups who don't appear in the other groups yet
Also, return groups with a different group_source_id in granted_via_*, it was forgotten
…opagation

So we can test viewPermission with can_request_help_to in the computed group with propagation
… origins.

It simplifies the query and the code
@GeoffreyHuck GeoffreyHuck changed the title [WIP] Get permission service: clean "can_request_help" usag [WIP] Get permission service: clean "can_request_help" usage Sep 11, 2023
@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (cb9e4c9) 100.00% compared to head (dd8741a) 100.00%.
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1006   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          230       230           
  Lines        13847     13893   +46     
=========================================
+ Hits         13847     13893   +46     
Files Changed Coverage Δ
app/api/groups/get_permissions.go 100.00% <100.00%> (ø)
app/database/item_store.go 100.00% <100.00%> (ø)
app/database/user.go 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GeoffreyHuck GeoffreyHuck changed the title [WIP] Get permission service: clean "can_request_help" usage Get permission service: clean "can_request_help" usage Sep 11, 2023
Copy link
Contributor

@smadbe smadbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You write in the PR:

Format of can_request_help_to in response

The fields are now always present:

  • id always set
  • name set or null if not visible
  • is_all_users_group to true or false depending on the case

At other places of the API, when an attribute is not visible, it is omitted (not given)... null is reserved for cases when a value is visible but null (the db value).

app/api/groups/get_permissions_can_request_help_to.feature Outdated Show resolved Hide resolved
app/api/groups/get_permissions_can_request_help_to.feature Outdated Show resolved Hide resolved
And the response at $.granted.can_request_help_to should be "null"
And the response at $.granted.can_request_help_to should be:
| id | name | is_all_users_group |
| @HelperGroup | | false |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this makes it difficult for me to check if this return a tuple (as requested) or just an array with one tuple (which would be more consistent with the other tables).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with <undefined>, see comment below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you didn't get my point. My question was : how can I know reading this if you checking for a tuple<id, name, is_all_users_group> or an array containing one tuple<id, name, is_all_users_group> ? What would be the different in the rule?

Copy link
Contributor Author

@GeoffreyHuck GeoffreyHuck Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is in the JSONPath. To retrieve an array, there is a [*] at the end of the JSONPath:

  • $.granted.can_request_help_to is an object
  • $.granted_via_membership.can_request_help_to[*] is an array

EDIT: I just checked and it works without the [*]. So

  • Either we intentionally put the [*] when we want an array
  • Or, we create a different feature for arrays. The code is basically doing a if (is_array) else {} already, so this might be a better solution

EDIT 2: Implemented as JSON checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

app/api/groups/get_permissions_can_request_help_to.feature Outdated Show resolved Hide resolved
So we can differentiate between null, empty arrays and empty strings
@GeoffreyHuck
Copy link
Contributor Author

GeoffreyHuck commented Sep 12, 2023

The ways to check for null, empty arrays, undefined fields, and empty strings have been uniformed:

  • <null> for null
  • [] for empty array
  • <undefined> for when the field is not present
  • `` nothing for an empty string

The feature the response should not be defined at JSONPath have been deleted in favor of the response at JsonPath should be "<undefined>" so we make the checks in the same way whether we check for a value or in an array with a table:

the response at $.groups[*] should be:
| id | name        |
| 1  | AAA         |
| 2  | <undefined> |

For the same reason, the empty array is checked with a special value instead of another feature, so we can check for empty arrays in an array.

To comply with the architecture decision
We use <undefined> to represent a field that is not present, so we can distinguish it with null
…ature

To uniformize the way we check for undefined path in arrays
And the response at $.granted_via_self.can_request_help_to[*] should be "[]"
And the response at $.granted.can_request_help_to should be "<null>"
And the response at $.granted_via_group_membership.can_request_help_to[*] should be "[]"
And the response at $.granted_via_item_unlocking.can_request_help_to[*] should be "[]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not $.granted_via_item_unlocking.can_request_help_to should be "[]" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

And the response at $.granted.can_request_help_to should be "null"
And the response at $.granted.can_request_help_to should be:
| id | name | is_all_users_group |
| @HelperGroup | | false |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you didn't get my point. My question was : how can I know reading this if you checking for a tuple<id, name, is_all_users_group> or an array containing one tuple<id, name, is_all_users_group> ? What would be the different in the rule?

Copy link
Contributor

@smadbe smadbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly questions actually...

This makes it clearer when we test single objects, rather than using an array
It's clearer that we are testing a single object and not an array with one entry
@see #1006 (comment)
…t we are testing an array

The check for single object with this feature has been disabled, it should now be tested with featuer allowing to check JSON at a JSONPath
@GeoffreyHuck GeoffreyHuck merged commit 73c262c into master Sep 13, 2023
4 checks passed
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.

Get permission service: clean "can_request_help" usage
2 participants