Skip to content

[PROD RELEASE] - WM related updates #740

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/code_reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: AI PR Reviewer

on:
pull_request:
types:
- opened
- synchronize
permissions:
pull-requests: write
jobs:
tc-ai-pr-review:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: TC AI PR Reviewer
uses: topcoder-platform/tc-ai-pr-reviewer@master

Choose a reason for hiding this comment

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

Consider specifying a version tag instead of using @master for the topcoder-platform/tc-ai-pr-reviewer action to ensure stability and avoid unexpected changes.

with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # The GITHUB_TOKEN is there by default so you just need to keep it like it is and not necessarily need to add it as secret as it will throw an error. [More Details](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret)
LAB45_API_KEY: ${{ secrets.LAB45_API_KEY }}
exclude: "**/*.json, **/*.md, **/*.jpg, **/*.png, **/*.jpeg, **/*.bmp, **/*.webp" # Optional: exclude patterns separated by commas

Choose a reason for hiding this comment

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

Ensure that the exclude patterns are correctly formatted and cover all necessary file types that should be excluded from the review process. Double-check if any additional file types need to be added to the exclusion list.

1 change: 1 addition & 0 deletions app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const UserRoles = {
Manager: "Connect Manager",
User: "Topcoder User",
SelfServiceCustomer: "Self-Service Customer",
ProjectManager: "Project Manager",
};

const prizeSetTypes = {
Expand Down
4 changes: 2 additions & 2 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const elasticsearch = require("elasticsearch");

const projectHelper = require("./project-helper");
const m2mHelper = require("./m2m-helper");
const { hasAdminRole } = require("./role-helper");
const { hasAdminRole, hasProjectManagerRole } = require("./role-helper");

// Bus API Client
let busApiClient;
Expand Down Expand Up @@ -960,7 +960,7 @@ async function _ensureAccessibleForTaskChallenge(currentUser, challenge) {
}
const canAccesChallenge = _.isUndefined(currentUser)
? false
: currentUser.isMachine || hasAdminRole(currentUser) || !_.isEmpty(memberResources);
: currentUser.isMachine || hasAdminRole(currentUser) || hasProjectManagerRole(currentUser) || !_.isEmpty(memberResources);

Choose a reason for hiding this comment

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

There is a typo in the variable name canAccesChallenge. It should be canAccessChallenge to maintain consistency and readability.

if (!canAccesChallenge) {
throw new errors.ForbiddenError(`You don't have access to view this challenge`);
}
Expand Down
16 changes: 16 additions & 0 deletions src/common/role-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ function hasAdminRole(authUser) {
return false;
}

/**
* Check if the user has project manager role
* @param {Object} authUser the user
*/
function hasProjectManagerRole(authUser) {
if (authUser && authUser.roles) {
for (const role of authUser.roles) {
if (role.toLowerCase() === constants.UserRoles.ProjectManager.toLowerCase()) {

Choose a reason for hiding this comment

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

Consider using localeCompare for case-insensitive comparison instead of toLowerCase() to handle edge cases with locale-specific characters.

return true;
}
}
}
return false;
}

module.exports = {
hasAdminRole,
hasProjectManagerRole,
};
5 changes: 3 additions & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const PhaseAdvancer = require("../phase-management/PhaseAdvancer");
const { ChallengeDomain } = require("@topcoder-framework/domain-challenge");
const { QueryDomain } = require("@topcoder-framework/domain-acl");

const { hasAdminRole } = require("../common/role-helper");
const { hasAdminRole, hasProjectManagerRole } = require("../common/role-helper");
const {
enrichChallengeForResponse,
sanitizeRepeatedFieldsInUpdateRequest,
Expand Down Expand Up @@ -152,6 +152,7 @@ async function searchChallenges(currentUser, criteria) {
];

const _hasAdminRole = hasAdminRole(currentUser);
const _hasProjectManagerRole = hasProjectManagerRole(currentUser);

Choose a reason for hiding this comment

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

Consider checking if hasProjectManagerRole function is defined and imported correctly to ensure it works as expected.


const includedTrackIds = _.isArray(criteria.trackIds) ? criteria.trackIds : [];
const includedTypeIds = _.isArray(criteria.typeIds) ? criteria.typeIds : [];
Expand Down Expand Up @@ -588,7 +589,7 @@ async function searchChallenges(currentUser, criteria) {
// FIXME: Tech Debt
let excludeTasks = true;
// if you're an admin or m2m, security rules wont be applied
if (currentUser && (_hasAdminRole || _.get(currentUser, "isMachine", false))) {
if (currentUser && (_hasAdminRole || _hasProjectManagerRole || _.get(currentUser, "isMachine", false))) {

Choose a reason for hiding this comment

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

The variable _hasProjectManagerRole is used here, but it's not clear from the diff if it is defined or initialized anywhere in the code. Ensure that _hasProjectManagerRole is properly defined and initialized before this line to avoid potential runtime errors.

excludeTasks = false;
}

Expand Down