Skip to content

[$60]Forums tab must be displayed for all roles like copilot approver etc #4672

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
SathyaJayabal opened this issue Jul 22, 2020 · 7 comments
Closed

Comments

@SathyaJayabal
Copy link
Collaborator

Forums tab must be displayed for all roles like copilot approver etc
example:
https://www.topcoder.com/challenges/30133520
https://beta-community-app.topcoder.com/challenges/0c8061f0-076f-47d3-a901-7cf13f99500c
user: picachui (copilot and appprover for the contest)
Screenshot 2020-07-22 at 12 50 07 PM

@sushilshinde sushilshinde changed the title Forums tab must be displayed for all roles like copilot approver etc [$40]Forums tab must be displayed for all roles like copilot approver etc Jul 27, 2020
@crazyk07
Copy link

Contest https://www.topcoder.com/challenges/30134485 has been created for this ticket.

This is an automated message for crazyk via Topcoder X

@crazyk07
Copy link

Contest https://www.topcoder.com/challenges/30134485 has been updated - it has been assigned to cagdas001.

This is an automated message for crazyk via Topcoder X

@cagdas001
Copy link
Collaborator

cagdas001 commented Jul 27, 2020

cc @sushilshinde

TL;DR; Needs a backend change at resource-api

The current code uses challenge.userDetails.roles to check if user has a role for the challenge.

const roles = _.get(challenge, 'userDetails.roles') || [];

It fetches user challenges and populates this field from user challenges. (see below code block for more detail)

/* uch array contains challenges where the user is participating in
@@ -111,8 +124,8 @@ function getAllActiveChallengesDone(uuid, tokenV3) {
* challenges in an efficient way. */
if (uch) {
const map = {};
uch.forEach((item) => { map[item.id] = item; });
ch.forEach((item) => {
if (map[item.id]) {
/* It is fine to reassing, as the array we modifying is created just
* above within the same function. */
/* eslint-disable no-param-reassign */
item.users[user] = true;
item.userDetails = map[item.id].userDetails;
/* eslint-enable no-param-reassign */
}
});
}

The issue is that, V5 API doesn't return such a field in challenges. I have also checked the V4 API, it also doesn't return. Looks like these are very old codes, were added 1-3 years ago, so I guess userDetails is a very old field and is no longer in use.

However, we still need a way to get user's role(s) for a particular challenge. Challenge API doesn't return any helpful info. Looks like there is a function named getUserRolesInChallenge in topcoder-react-lib repo.

https://github.com/topcoder-platform/topcoder-react-lib/blob/50738814672941b0df4031bfd0713f931dc1bd74/src/services/challenges.js#L692-L711

  /**
   * Gets roles of a user in the specified challenge. The user tested is
   * the owner of authentication token used to instantiate the service.
   *
   * Notice, if you have already loaded the challenge as that user, these roles
   * are attached to the challenge object under `userDetails.roles` path during
   * challenge normalization. However, if you have not, this method is the most
   * efficient way to get them, as it by-passes any unnecessary normalizations
   * of the challenge object.
   *
   * @param {Number} challengeId Challenge ID.
   */
  async getUserRolesInChallenge(challengeId) {
    const user = decodeToken(this.private.tokenV3);
    const url = `/resources?challengeId=${challengeId}?memberHandle=${user.handle}`;
    const resources = await this.private.apiV5.get(url);
    if (resources) return _.map(resources, 'roleId');
    throw new Error(`Failed to fetch user role from challenge #${challengeId}`);
  }
}

This is exactly what we're looking for. However, there is an issue with resource-api. It only returns the Submitter role if the user is not an admin or machine. So, we can't get the roleId of other roles like co-pilot etc.

https://github.com/topcoder-platform/resources-api/blob/8637689677040118135c4f184b44812008c5d86f/src/services/ResourceService.js#L58-L64

  if (!currentUser || (!currentUser.isMachine && !helper.hasAdminRole(currentUser))) {
    // await checkAccess(currentUser, resources)
    // if not admin, and not machine, only return submitters
    boolQuery.push({ match_phrase: { roleId: config.SUBMITTER_RESOURCE_ROLE_ID } })
  } else if (roleId) {
    boolQuery.push({ match_phrase: { roleId } })
  }

Maybe we can make a change at resource-api, if I'm querying another user's resources it's understandable to return only Submitter roles, however, if I'm querying my own resources (this is our case), I think it can return all the resources with all roles. Currently it only returns resources with Submitter roles, even if I'm querying with my own memberId

I can make the above change at the resource-api if someone confirms

@sushilshinde sushilshinde changed the title [$40]Forums tab must be displayed for all roles like copilot approver etc [$60]Forums tab must be displayed for all roles like copilot approver etc Jul 29, 2020
@sushilshinde
Copy link
Collaborator

@rootelement will confirm that. That's a good analysis @cagdas001

@cagdas001
Copy link
Collaborator

PR (topcoder-react-lib): topcoder-platform/topcoder-react-lib#214

Use this version of topcoder-react-lib when testing the community-app (you can add it as local dependency)

sushilshinde added a commit to topcoder-platform/topcoder-react-lib that referenced this issue Aug 5, 2020
sushilshinde added a commit that referenced this issue Aug 5, 2020
@SathyaJayabal
Copy link
Collaborator Author

verified on beta
Screenshot 2020-08-05 at 11 12 31 AM

@crazyk07
Copy link

crazyk07 commented Aug 6, 2020

Payment task has been updated: https://software.topcoder.com/review/actions/ViewProjectDetails?pid=30134485

This is an automated message for crazyk via Topcoder X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants