Skip to content

Conversation

@justsomeboy26
Copy link

P1B: Starter Task: Refactoring PR

1. Issue

Please provide a link to the associated GitHub issue:

Link to the associated GitHub issue:
#272

Full path to the refactored file:
src/privileges/topics.js

What do you think this file does?
This file topics.js seems to check if the user has permissions to do different actions related to topics. There are checks of privileges of users using their user id that happen throughout this file. As for the specific canDelete function, I believe it is run to check if a user is allowed to delete a topic.

What is the scope of your refactoring within that file?
The return line of the function canDelete.

Which Qlty‑reported issue did you address?
Complex Binary Expression 170 in privsTopics.canDelete().

2. Refactoring

How did the specific issue you chose impact the codebase’s adaptability?
The specific issue that I chose impacted the codebase's adaptability because it was hard to interpret what was being returned by the function canDelete as it was a large binary expression.

What changes did you make to resolve the issue?
I split the central section of the binary expression into a const labeled "MiddleExpression" and then checked if the user is a moderator and stored that into a more interpretable const called "roleCheck" and returned allowedTo[0] && roleCheck.

How do your changes improve adaptability? Did you consider alternatives?
My changes improve adaptability by making the function canDelete easier to understand for someone reading the code, as the value being returned uses fewer binary operators, and the name of what's being checked is clearer.

3. Validation

How did you trigger the refactored code path from the UI?
I signed into a non-admin account and then posted a topic, then deleted it. This triggered my print into ./nodebb log.

Attach a screenshot of the logs and UI demonstrating the trigger.
image

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.js> showing fewer reported issues after the changes.
image

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17603617301

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 78.542%

Totals Coverage Status
Change from base Build 17435863312: 0.01%
Covered Lines: 24698
Relevant Lines: 29608

💛 - Coveralls

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.

2 participants