Skip to content

Remove code duplication on temp mod role revocation failure #414

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

Closed
Zabuzard opened this issue Mar 15, 2022 · 12 comments · Fixed by #417
Closed

Remove code duplication on temp mod role revocation failure #414

Zabuzard opened this issue Mar 15, 2022 · 12 comments · Fixed by #417
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers priority: major

Comments

@Zabuzard
Copy link
Member

Overview

Sonar correctly flags this as code duplication:

sonar

We should unify this section. Maybe move it into ModerationUtils as a helper like "handle temporary moderation role revocation failure" or similar.

It is currently causing our quality gate to fail (since I made some adjustments on its strictness)

@Zabuzard Zabuzard added enhancement New feature or request good first issue Good for newcomers priority: normal labels Mar 15, 2022
@Zabuzard Zabuzard added this to the Improvement phase 1 milestone Mar 15, 2022
@Tais993
Copy link
Member

Tais993 commented Mar 15, 2022

I honestly disagree, just like you used to, see here.

They aren't the same thing, and nothing is wrong with handling them differently.
I rather see a way to suppress them than "fix" them.

@Zabuzard
Copy link
Member Author

Zabuzard commented Mar 15, 2022

@Tais993 Suppress is the definitely wrong action, instead it should be acknownledged as wont-fix in sonar itself.

That said, I definitely agree to wont-fix on the other duplicate it flagged (the arg extraction of the command options). But for this one I genuinely agree with Sonar. They are identical and will stay identical. This is the failure handle for removing a temporary mod revocation role from a member.

In particular, if we introduce another temp mod action that is based on roles, it will get the identical failure handle -> it should be one place and not duplicated.

@interacsion
Copy link
Contributor

I looked a bit into it, and if we want to move the method into ModerationUtils we'll have to make RevocableModerationAction public. another alternative is to make the method a static method of RevocableModerationAction.

@Tais993
Copy link
Member

Tais993 commented Mar 16, 2022

another alternative is to make the method a static method of RevocableModerationAction.

Doesn't sound like a good idea, it probably makes a lot more sense to become an utility emthod in ModerationUtils

@interacsion
Copy link
Contributor

interacsion commented Mar 16, 2022

I agree, it sounds a bit sketchy, I just wanted to point it out :) the thing is, this logic is (and will probably stay) exclusive to RevocableModerationAction's implementations, as far as I can see.
so maybe putting it in a more specific scope is the right idea.

@Zabuzard
Copy link
Member Author

Should probably end up as utiltiy in the temp mod package thing.

@interacsion
Copy link
Contributor

In a completely new class?

@Zabuzard
Copy link
Member Author

Zabuzard commented Mar 16, 2022

Sure, why not. Or just make it public in the moderation util. I dont really see a big issue here. Its a bit unfortunate that there is no concept of "subpackage visibility" but it is what it is. The ModUtils helper is only really meaningful for mod stuff anyways and there are already classes outside of the package using it, no? Doesnt really hurt if the subpackage mod/temp also starts using it, imo.

As in, adding a void handleTempModRoleRevocationFailure(Throwable failure) to ModerationUtils and then giving that as method reference: queue(..., ModerationUtils::handleTempModRoleRevocationFailure) or similar.

@interacsion
Copy link
Contributor

only problem I see with that is that TermporaryBanAction has a slightly different logic than TemporaryMuteAction and TermoraryQuarantineAction

@Zabuzard
Copy link
Member Author

Thats because it is not a "handleTempModRoleRevocationFailure" (emphasis on role for role-based). Hence it is also not a duplicate. I havent checked its failure handler, is it that similar? I didnt really intend to unify it here as well.

@interacsion
Copy link
Contributor

the thing is, I got a bit confused about the method reference, as all of the three actions share one queue() call.

@interacsion
Copy link
Contributor

I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers priority: major
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants