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

add didUpdateRolePermissions event #8333

Merged
merged 5 commits into from Oct 20, 2020

Conversation

petersg83
Copy link
Contributor

No description provided.

@petersg83 petersg83 requested a review from a team as a code owner October 14, 2020 13:48
@petersg83 petersg83 force-pushed the telemetry/didUpdateRolePermissions branch from 78c40f9 to 23ed86e Compare October 14, 2020 14:37
@petersg83 petersg83 requested a review from Convly October 14, 2020 14:37
Convly
Convly previously approved these changes Oct 14, 2020
Copy link
Member

@Convly Convly left a comment

Choose a reason for hiding this comment

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

LGTM, waiting for the tests

@alexandrebodin
Copy link
Member

I will review it before it is merged

@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #8333 into master will increase coverage by 0.07%.
The diff coverage is 98.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8333      +/-   ##
==========================================
+ Coverage   33.19%   33.27%   +0.07%     
==========================================
  Files        1220     1220              
  Lines       13618    13625       +7     
  Branches     1357     1357              
==========================================
+ Hits         4521     4534      +13     
+ Misses       8212     8207       -5     
+ Partials      885      884       -1     
Flag Coverage Δ
#front 24.72% <ø> (ø)
#unit 54.69% <98.11%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/strapi-admin/services/permission.js 71.64% <ø> (-5.93%) ⬇️
packages/strapi-admin/services/role.js 96.99% <98.00%> (+2.67%) ⬆️
packages/strapi-admin/controllers/role.js 47.16% <100.00%> (ø)
packages/strapi-admin/services/metrics.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fad9fda...54f83ea. Read the comment docs.

@petersg83 petersg83 force-pushed the telemetry/didUpdateRolePermissions branch from 23ed86e to a510ce0 Compare October 15, 2020 09:49
@petersg83 petersg83 requested a review from Convly October 15, 2020 09:49
@petersg83 petersg83 force-pushed the telemetry/didUpdateRolePermissions branch 3 times, most recently from 7231017 to a1dc225 Compare October 15, 2020 14:19
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

It would be simpler to send the event from the service as it is where the decision can be made without leaking internal state. to the caller (controller in this case).

Another approach (I like it but I think it's to soon) is to use the eventHub to send a didAssignPermission like event and have a listener that will check the event and send telemetry if necessary

@petersg83
Copy link
Contributor Author

It was in the service at the begining but @Convly pointed some problems with that : #8333 (comment)
What do you think about that?

@alexandrebodin
Copy link
Member

alexandrebodin commented Oct 16, 2020

It was in the service at the begining but @Convly pointed some problems with that : #8333 (comment)
What do you think about that?

We can check that the existingPermissions count is > 0 to send the event I believe

@petersg83
Copy link
Contributor Author

petersg83 commented Oct 16, 2020

We can check that the existingPermissions count is > 0 to send the event I believe

We would miss the edge case where a role has, at some point, 0 permissions and is then updated with some.
If you're ok with that because you find the code cleaner, I'm ok with that too.

Signed-off-by: Pierre Noël <petersg83@gmail.com>
packages/strapi-admin/services/role.js Outdated Show resolved Hide resolved
packages/strapi-admin/services/permission.js Outdated Show resolved Hide resolved
Signed-off-by: Pierre Noël <petersg83@gmail.com>
@petersg83
Copy link
Contributor Author

I think the best place would still have been in the controller. As it is a service, anyone can use it in a plugin or else. So the logic way for this telemetry would be, for me, only with the route which the admin panel calls.

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

I'm going to be picky here but I think this need a refactoring.

We should have the assignPermissions and addPermissions methods in the role service and those could use the permissions service for createMany (which would not have a role there) Let's decouple those two services

@petersg83 petersg83 force-pushed the telemetry/didUpdateRolePermissions branch 2 times, most recently from 5f9b6c8 to 8436cb1 Compare October 19, 2020 14:49
Signed-off-by: Pierre Noël <petersg83@gmail.com>
@petersg83 petersg83 force-pushed the telemetry/didUpdateRolePermissions branch from 8436cb1 to 907d6c9 Compare October 19, 2020 15:02
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

last comment :)

packages/strapi-admin/services/role.js Outdated Show resolved Hide resolved
Signed-off-by: Pierre Noël <petersg83@gmail.com>
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: core:admin Source is core/admin package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants