Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: Return DisplayName and Name in the roles endpoint #1328

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

Merged
merged 2 commits into from
May 6, 2022

Conversation

BrunoQuaresma
Copy link
Collaborator

No description provided.

@BrunoQuaresma BrunoQuaresma requested review from Emyrk and a team May 6, 2022 18:10
@BrunoQuaresma BrunoQuaresma self-assigned this May 6, 2022
@codecov
Copy link

codecov bot commented May 6, 2022

Codecov Report

Merging #1328 (85d6f69) into main (57bb108) will increase coverage by 8.47%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1328      +/-   ##
==========================================
+ Coverage   58.09%   66.56%   +8.47%     
==========================================
  Files         282      280       -2     
  Lines       18521    18383     -138     
  Branches      231      235       +4     
==========================================
+ Hits        10759    12237    +1478     
+ Misses       6601     4902    -1699     
- Partials     1161     1244      +83     
Flag Coverage Δ
unittest-go-macos-latest 53.75% <100.00%> (+0.07%) ⬆️
unittest-go-postgres- 65.15% <100.00%> (?)
unittest-go-ubuntu-latest 56.18% <100.00%> (+0.12%) ⬆️
unittest-go-windows-2022 ?
unittest-js 73.67% <ø> (+0.52%) ⬆️
Impacted Files Coverage Δ
coderd/rbac/builtin.go 92.70% <100.00%> (+0.27%) ⬆️
coderd/roles.go 100.00% <100.00%> (ø)
coderd/users.go 61.36% <100.00%> (ø)
codersdk/roles.go 80.64% <100.00%> (+7.91%) ⬆️
cli/configssh.go 62.04% <0.00%> (-6.57%) ⬇️
codersdk/provisionerdaemons.go 61.97% <0.00%> (-5.64%) ⬇️
pty/ptytest/ptytest.go 86.95% <0.00%> (-4.35%) ⬇️
site/src/xServices/users/usersXService.ts 75.00% <0.00%> (-4.17%) ⬇️
cli/templateinit.go 58.62% <0.00%> (-3.45%) ⬇️
site/src/pages/UsersPage/UsersPage.tsx 75.86% <0.00%> (-3.31%) ⬇️
... and 29 more

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 57bb108...85d6f69. Read the comment docs.

@BrunoQuaresma
Copy link
Collaborator Author

BrunoQuaresma commented May 6, 2022

Closes #1329

return roles, json.NewDecoder(res.Body).Decode(&roles)
}

func RolesFromName(roleNames []string) []Role {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created this function to use in the endpoints to not break any internal implementation.

return roles, json.NewDecoder(res.Body).Decode(&roles)
}

func RolesFromName(roleNames []string) []Role {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of having this function that may convert a role name to a role, you should just have a function in the rbac package that returns all site role objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting. How would you call that?

Copy link
Member

Choose a reason for hiding this comment

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

What I'm trying to say is we should avoid having to first get the "role names" and then convert those to "roles" in a potentially lossy fashion. We should just have a function that returns the roles instead of a function that returns the role names in the rbac package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it. I made the update, please let me know what you think about the changes. Merging it for now.

@BrunoQuaresma BrunoQuaresma enabled auto-merge (squash) May 6, 2022 19:17
@BrunoQuaresma BrunoQuaresma merged commit 0080658 into main May 6, 2022
@BrunoQuaresma BrunoQuaresma deleted the bq/return-role-display-name branch May 6, 2022 19:18
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
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