-
Notifications
You must be signed in to change notification settings - Fork 19
[1171- STORY ]- User Session Implementation added. #473
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a24b42b
user-sessions table added to user service
VISHNUDAS-tunerlabs 12db6ce
user sessions
VISHNUDAS-tunerlabs b11acb2
changes pushed for internal api testing. code clean up and optimisati…
VISHNUDAS-tunerlabs 8114f1c
local merge check
VISHNUDAS-tunerlabs 1d73640
code clean up before merge
VISHNUDAS-tunerlabs 741614b
internal url updated
VISHNUDAS-tunerlabs 2ab1c31
develop branch merged and conflicts addressed
VISHNUDAS-tunerlabs a9ae2e7
user table and related api changes
VISHNUDAS-tunerlabs 49497e1
configurable active session check added
VISHNUDAS-tunerlabs 3663260
parse device info
VISHNUDAS-tunerlabs ff92666
device info
VISHNUDAS-tunerlabs 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| FROM node:16 | ||
| FROM node:20 | ||
|
|
||
| #Set working directory | ||
| WORKDIR /var/src/ | ||
|
|
||
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
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
54 changes: 54 additions & 0 deletions
54
src/database/migrations/20240326110128-create-user-sessions-table.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,54 @@ | ||
| 'use strict' | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { | ||
| async up(queryInterface, Sequelize) { | ||
| await queryInterface.createTable('user_sessions', { | ||
| id: { | ||
| type: Sequelize.INTEGER, | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| autoIncrement: true, | ||
| }, | ||
| user_id: { | ||
| type: Sequelize.INTEGER, | ||
| allowNull: false, | ||
| }, | ||
| started_at: { | ||
| type: Sequelize.BIGINT, | ||
VISHNUDAS-tunerlabs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| allowNull: false, | ||
| }, | ||
| ended_at: { | ||
| type: Sequelize.BIGINT, | ||
| allowNull: true, | ||
| }, | ||
| token: { | ||
| type: Sequelize.TEXT, | ||
| allowNull: true, | ||
| }, | ||
| device_info: { | ||
| type: Sequelize.JSONB, | ||
| allowNull: true, | ||
| }, | ||
| refresh_token: { | ||
| type: Sequelize.TEXT, | ||
| allowNull: true, | ||
| }, | ||
| created_at: { | ||
| allowNull: false, | ||
| type: Sequelize.DATE, | ||
| }, | ||
| updated_at: { | ||
| allowNull: false, | ||
| type: Sequelize.DATE, | ||
| }, | ||
| deleted_at: { | ||
| type: Sequelize.DATE, | ||
| }, | ||
| }) | ||
| }, | ||
|
|
||
| async down(queryInterface, Sequelize) { | ||
| await queryInterface.dropTable('user_sessions') | ||
| }, | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
src/database/migrations/20240328084048-update-session-permissions.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,48 @@ | ||
| 'use strict' | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { | ||
| async up(queryInterface, Sequelize) { | ||
| try { | ||
| const permissionsData = [ | ||
| { | ||
| code: 'get_user_sessions', | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| status: 'ACTIVE', | ||
| }, | ||
| { | ||
| code: 'validate_user_sessions', | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| status: 'ACTIVE', | ||
| }, | ||
| ] | ||
|
|
||
| // Batch insert permissions | ||
| await queryInterface.bulkInsert( | ||
| 'permissions', | ||
| permissionsData.map((permission) => ({ | ||
| ...permission, | ||
| created_at: new Date(), | ||
| updated_at: new Date(), | ||
| })) | ||
| ) | ||
| } catch (error) { | ||
| console.error('Error in migration:', error) | ||
| throw error | ||
| } | ||
| }, | ||
|
|
||
| async down(queryInterface, Sequelize) { | ||
| try { | ||
| // Rollback migration by deleting all permissions | ||
| await queryInterface.bulkDelete('permissions', null, {}) | ||
| } catch (error) { | ||
| console.error('Error in rollback migration:', error) | ||
| throw error | ||
| } | ||
| }, | ||
| } |
139 changes: 139 additions & 0 deletions
139
src/database/migrations/20240328084246-update-session-role-permission.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,139 @@ | ||
| 'use strict' | ||
|
|
||
| require('module-alias/register') | ||
| require('dotenv').config() | ||
| const common = require('@constants/common') | ||
| const Permissions = require('@database/models/index').Permission | ||
|
|
||
| const getPermissionId = async (module, request_type, api_path) => { | ||
| try { | ||
| const permission = await Permissions.findOne({ | ||
| where: { module, request_type, api_path }, | ||
| }) | ||
| if (!permission) { | ||
| throw new Error( | ||
| `Permission not found for module: ${module}, request_type: ${request_type}, api_path: ${api_path}` | ||
| ) | ||
| } | ||
| return permission.id | ||
| } catch (error) { | ||
| throw new Error(`Error while fetching permission: ${error.message}`) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| up: async (queryInterface, Sequelize) => { | ||
| try { | ||
| const rolePermissionsData = await Promise.all([ | ||
| { | ||
| role_title: common.MENTOR_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
| { | ||
| role_title: common.ORG_ADMIN_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
| { | ||
| role_title: common.USER_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
| { | ||
| role_title: common.ADMIN_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
| { | ||
| role_title: common.SESSION_MANAGER_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
| { | ||
| role_title: common.MENTEE_ROLE, | ||
| permission_id: await getPermissionId('account', ['GET'], '/user/v1/account/sessions'), | ||
| module: 'account', | ||
| request_type: ['GET'], | ||
| api_path: '/user/v1/account/sessions', | ||
| }, | ||
|
|
||
| { | ||
| role_title: common.MENTOR_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| { | ||
| role_title: common.MENTEE_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| { | ||
| role_title: common.ORG_ADMIN_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| { | ||
| role_title: common.USER_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| { | ||
| role_title: common.ADMIN_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| { | ||
| role_title: common.SESSION_MANAGER_ROLE, | ||
| permission_id: await getPermissionId('account', ['POST'], '/user/v1/account/validateUserSession'), | ||
| module: 'account', | ||
| request_type: ['POST'], | ||
| api_path: '/user/v1/account/validateUserSession', | ||
| }, | ||
| ]) | ||
|
|
||
| await queryInterface.bulkInsert( | ||
| 'role_permission_mapping', | ||
| rolePermissionsData.map((data) => ({ | ||
| ...data, | ||
| created_at: new Date(), | ||
| updated_at: new Date(), | ||
| created_by: 0, | ||
| })) | ||
| ) | ||
| } catch (error) { | ||
| console.log(error) | ||
| console.error(`Migration error: ${error.message}`) | ||
| throw error | ||
| } | ||
| }, | ||
|
|
||
| down: async (queryInterface, Sequelize) => { | ||
| try { | ||
| await queryInterface.bulkDelete('role_permission_mapping', null, {}) | ||
| } catch (error) { | ||
| console.error(`Rollback migration error: ${error.message}`) | ||
| throw error | ||
| } | ||
| }, | ||
| } |
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.