-
Notifications
You must be signed in to change notification settings - Fork 14
MOSIP-45245-Github Trakker add Apis to fetch user details in backend along with roles #45
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
kharodejayesh
wants to merge
3
commits into
mosip:develop
Choose a base branch
from
kharodejayesh:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const USER_ROLES = [ | ||
| 'Developer', | ||
| 'Tech Lead', | ||
| 'Architect', | ||
| 'Product Owner', | ||
| 'Leadership', | ||
| 'QA Engineer', | ||
| 'DevOps Engineer', | ||
| ]; | ||
|
|
||
| function isValidUserRole(role) { | ||
| return USER_ROLES.includes(role); | ||
| } | ||
|
|
||
| module.exports = { | ||
| USER_ROLES, | ||
| isValidUserRole, | ||
| }; |
3 changes: 3 additions & 0 deletions
3
github-activity-tracker/backend/migrations/005_add_name_to_github_users.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- GitHub profile display name (from GET /users/{login} or GraphQL User.name). | ||
| ALTER TABLE github_users | ||
| ADD COLUMN IF NOT EXISTS name VARCHAR(255); |
6 changes: 6 additions & 0 deletions
6
github-activity-tracker/backend/migrations/006_add_role_to_github_users.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- Job role for team members (set manually until admin update API exists). | ||
| -- Allowed values: Developer, Tech Lead, Architect, Product Owner, Leadership, QA Engineer, DevOps Engineer | ||
| ALTER TABLE github_users | ||
| ADD COLUMN IF NOT EXISTS role VARCHAR(50); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_github_users_role ON github_users(role); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
github-activity-tracker/backend/routes/userNameSyncRoute.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Route: POST /admin/sync/user-names | ||
| * Backfills GitHub profile display names for users missing name in github_users. | ||
| */ | ||
| const express = require('express'); | ||
| const { backfillMissingUserNames } = require('../services/githubUserService'); | ||
| const { HTTP, STATUS } = require('../config/errorCodes'); | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| router.post('/admin/sync/user-names', async (req, res) => { | ||
| try { | ||
| const result = await backfillMissingUserNames(); | ||
|
|
||
| return res.json({ | ||
| status: STATUS.SUCCESS, | ||
| ...result, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error backfilling GitHub user names:', error); | ||
|
|
||
| return res.status(HTTP.INTERNAL_SERVER_ERROR).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'Failed to backfill GitHub user names', | ||
| error: process.env.NODE_ENV === 'development' ? error.message : undefined, | ||
| }); | ||
| } | ||
| }); | ||
|
kharodejayesh marked this conversation as resolved.
|
||
|
|
||
| module.exports = router; | ||
100 changes: 100 additions & 0 deletions
100
github-activity-tracker/backend/routes/userRoleRoute.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * Routes: | ||
| * GET /admin/users/:login/role – fetch role for a GitHub user | ||
| * POST /admin/users/role – assign role to a GitHub user | ||
| */ | ||
| const express = require('express'); | ||
| const { getUserRole, setUserRole } = require('../services/userRoleService'); | ||
| const { USER_ROLES } = require('../config/userRoles'); | ||
| const { HTTP, STATUS } = require('../config/errorCodes'); | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| router.get('/admin/users/:login/role', async (req, res) => { | ||
| try { | ||
| const { login } = req.params; | ||
|
|
||
| if (!login) { | ||
| return res.status(HTTP.BAD_REQUEST).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'login is required', | ||
| }); | ||
| } | ||
|
|
||
| const user = await getUserRole(login); | ||
|
|
||
| if (!user) { | ||
| return res.status(HTTP.NOT_FOUND).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'User not found', | ||
| }); | ||
| } | ||
|
|
||
| return res.json({ | ||
| status: STATUS.SUCCESS, | ||
| user, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error fetching user role:', error); | ||
|
|
||
| return res.status(HTTP.INTERNAL_SERVER_ERROR).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'Failed to fetch user role', | ||
| error: process.env.NODE_ENV === 'development' ? error.message : undefined, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| router.post('/admin/users/role', async (req, res) => { | ||
| try { | ||
| const { login, role } = req.body || {}; | ||
|
|
||
| if (!login) { | ||
| return res.status(HTTP.BAD_REQUEST).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'login is required in request body', | ||
| }); | ||
| } | ||
|
|
||
| if (!role) { | ||
| return res.status(HTTP.BAD_REQUEST).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'role is required in request body', | ||
| allowed_roles: USER_ROLES, | ||
| }); | ||
| } | ||
|
|
||
| const user = await setUserRole({ login, role }); | ||
|
|
||
| if (!user) { | ||
| return res.status(HTTP.NOT_FOUND).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'User not found', | ||
| }); | ||
| } | ||
|
|
||
| return res.json({ | ||
| status: STATUS.SUCCESS, | ||
| message: 'Role assigned successfully', | ||
| user, | ||
| }); | ||
| } catch (error) { | ||
| if (error.message === 'Invalid role value') { | ||
| return res.status(HTTP.BAD_REQUEST).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'Invalid role value', | ||
| allowed_roles: USER_ROLES, | ||
| }); | ||
| } | ||
|
|
||
| console.error('Error assigning user role:', error); | ||
|
|
||
| return res.status(HTTP.INTERNAL_SERVER_ERROR).json({ | ||
| status: STATUS.ERROR, | ||
| message: 'Failed to assign user role', | ||
| error: process.env.NODE_ENV === 'development' ? error.message : undefined, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| module.exports = router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.