Skip to content

Conversation

@ssura1
Copy link

@ssura1 ssura1 commented Jan 24, 2026

handleForbiddenApi - handles 403 API responses for authenticated users

handleForbiddenPage - 403 page renders for unauthenticated users

handleUnauthenticated - responses for unauthenticated users (API & redirect cases)

Logic:

  • fires the plugin hooks
  • checks if headers already sent
  • determines if user authenticated
  • assigns current handler function

P1B: Starter Task: Refactoring PR

Use this pull request template to briefly answer the questions below in one to two sentences each.
Feel free to delete this text at the top after filling out the template.

You are not permitted to use generative AI services (e.g., ChatGPT) to compose the answers.
Any such use will be treated as a violation of academic integrity.

1. Issue

Link to the associated GitHub issue: #175

Full path to the refactored file: src/controllers/helpers.js

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)
Handles errors (unauthorized or bad forms) and formatting

What is the scope of your refactoring within that file?
I refactored some of the authentication logic and forbidden page logic

I made 3 new functions - handleForbiddenApi, handleForbiddenPage, handleUnauthenticated
(Name specific functions/blocks/regions touched.)

Which Qlty‑reported issue did you address?
Function with high complexity (count = 14)
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
It made it more understandable so people understand what happens in different cases.

What changes did you make to resolve the issue?
I got rid of the loops and used the variables of req to check if the user was authenticated, if the case was an API case.

How do your changes improve maintainability? Did you consider alternatives?
On our backend we can see what kind of errors users are running into.

3. Validation

How did you trigger the refactored code path from the UI?
Tried logging into an account that I didn't have access to

Attach a screenshot of the logs and UI demonstrating the trigger.
(If you refactored a public/src/ file (front-end related file), watch logging via DevTools (Ctrl+Shift+I to open and then navigate to the 'Console' tab). If you refactored a src/ file, watch logging via ./nodebb log. Include the relevant UI view. Temporary logs should be removed before final commit.)
Screenshot 2026-01-23 235535

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

handleForbiddenApi - handles 403 API responses for authenticated users

handleForbiddenPage - 403 page renders for unauthenticated users

handleUnauthenticated - responses for unauthenticated users (API & redirect cases)

Logic:
- fires the plugin hooks
- checks if headers already sent
- determines if user authenticated
- assigns current handler function
@ssura1
Copy link
Author

ssura1 commented Jan 24, 2026

nodebb log
image

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.

1 participant