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

Revisited add-admin action #241

Merged
merged 93 commits into from
Jun 14, 2024
Merged

Revisited add-admin action #241

merged 93 commits into from
Jun 14, 2024

Conversation

codethulu
Copy link
Contributor

@codethulu codethulu commented May 2, 2024

Overview

Created an add_user action, which simply creates a user account. The on_add_admin method then is responsible for calling this method, and then promoting the user to admin level. This behaviour has effectively been split.

Rationale

We want an action to change an existing user to an admin and an action to create a user. And if the user already exists, we don’t want to update the password. If the user doesn’t exist, we can to create the user and generate a random secure password for them.

Juju Events Changes

N/A

Module Changes

N/A

Library Changes

No significant changes, just updates to be consistent with main.

Checklist

@codethulu codethulu changed the title drafted approach to re-do add-admin user action Revisited add-admin action May 15, 2024
@codethulu
Copy link
Contributor Author

codethulu commented May 15, 2024

There were a few methods that needed to be considered. In the end, after discussion with @nrobinaubertin and @amandahla I have decided to create a new rake patch -

This approach was chosen for a few reasons:

  • This does not append to the end of a pre-existing file, but rather places additional rake commands in a canonical.rake file. This is a more robust solution as it is not dependent on replacing some code. Can lead to less conflicts, as all additional processes are in one file.
  • Clear to see all (non-merged upstream) rake commands we have written, in one file.
  • Clearly defines a user:create and admin:promote endpoints. Although technically, we could use the admin:create endpoint and pass in different parameters, to create a user and input n to not grant admin privileges, this does not seem entirely clear in the code without referencing the upstream definition of the method. Additionally, both me and Amanda agree that such methods, especially the user:create, should exist in the user rake commands. I want to submit a PR to discourse to attempt to have these supported upstream.
  • In addition, by using admin:create for both creating and promoting a user, we effectively have an un-changed on_add_admin_user method. By having clearly defined endpoints, I believe the code is better self documenting.

@codethulu
Copy link
Contributor Author

Additionally, the previous rake patch to add user:anonymize has been removed, since this has been merged to discourse in version 3.2.0, which is what we use in rockcraft.

@codethulu codethulu marked this pull request as ready for review May 15, 2024 16:28
@codethulu codethulu requested a review from a team as a code owner May 15, 2024 16:28
Copy link
Contributor

@mthaddon mthaddon left a comment

Choose a reason for hiding this comment

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

Haven't done a full review, but are we meaning to remove the anonymize_user.patch file here? Having a full description of the change and the rationale would be good to confirm what we're intending to do and why.

requirements.txt Outdated Show resolved Hide resolved
@nrobinaubertin
Copy link
Collaborator

rather places additional rake commands in a canonical.rake file

I would name it something like discourse-charm.rake to avoid tying it directly to the Canonical name (it's not a patch specifically for our needs but for the charm's needs)

discourse_rock/rockcraft.yaml Outdated Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
discourse_rock/patches/rake.patch Outdated Show resolved Hide resolved
Copy link
Contributor

@javierdelapuente javierdelapuente left a comment

Choose a reason for hiding this comment

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

A few more comments! It is on good track!

src/charm.py Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
tests/integration/test_users.py Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
tests/unit/test_charm.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@nrobinaubertin nrobinaubertin left a comment

Choose a reason for hiding this comment

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

I feel like the PR has out-of-scope changes (like Arturo mentioned). Is it too late to remove some of the changes (in the tests) to move them to another PR ?

discourse_rock/patches/discourse-charm.patch Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
Copy link
Contributor

Test coverage for 6df0442

Name              Stmts   Miss Branch BrPart  Cover   Missing
-------------------------------------------------------------
src/charm.py        371     41     94     15    88%   184, 192-193, 205, 337->345, 378->383, 395, 577-579, 584-585, 597-599, 604-605, 617-619, 642-644, 686->exit, 696->exit, 745-748, 758-759, 783-784, 796-797, 824-826, 828->833, 830-831, 873-874, 890-891, 901->exit, 915
src/database.py      29      1      8      1    95%   56
-------------------------------------------------------------
TOTAL               400     42    102     16    88%

Static code analysis report

Run started:2024-06-14 14:28:12.926870

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 2336
  Total lines skipped (#nosec): 2
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

@codethulu codethulu merged commit 9eaa5e1 into main Jun 14, 2024
20 checks passed
@codethulu codethulu deleted the feat/ISD-1064 branch June 14, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants