Skip to content

Commit add425d

Browse files
committed
fix service account use
1 parent ed0ae53 commit add425d

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

backend/managers/instances.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ async function getAllInstances(user, filters = {}) {
1111
let whereConditions = [];
1212
let params = [];
1313

14-
// If user is admin, show all instances
15-
if (user.role === 'ADMIN') {
14+
// If user is admin or service account, show all instances
15+
if (user.role === 'ADMIN' || user.role === 'SERVICE_ACCOUNT') {
1616
let baseQuery = `
1717
SELECT i.*,
1818
w.name as workshop_name,

backend/managers/teams.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const { search, searchAll, insert, update, deleteFrom, executeQuery } = require(
77
async function getAllTeams(user) {
88
let teams;
99

10-
// If user is admin, show all teams
11-
if (user.role === 'ADMIN') {
10+
// If user is admin or service account, show all teams
11+
if (user.role === 'ADMIN' || user.role === 'SERVICE_ACCOUNT') {
1212
teams = await searchAll('teams', [], [], { orderBy: 'team_number' });
1313
} else {
1414
// Get teams that user belongs to
@@ -397,9 +397,9 @@ async function getTeamStats() {
397397
* Check if user can access team
398398
*/
399399
async function canUserAccessTeam(userId, teamId) {
400-
// Admin can access all teams
400+
// Admin and service accounts can access all teams
401401
const user = await search('users', 'id', userId);
402-
if (user && user.role === 'ADMIN') {
402+
if (user && (user.role === 'ADMIN' || user.role === 'SERVICE_ACCOUNT')) {
403403
return true;
404404
}
405405

backend/managers/workshops.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const { search, searchAll, insert, update, deleteFrom, executeQuery } = require(
77
async function getAllWorkshops(user) {
88
let workshops;
99

10-
// If user is admin, show all workshops
11-
if (user.role === 'ADMIN') {
10+
// If user is admin or service account, show all workshops
11+
if (user.role === 'ADMIN' || user.role === 'SERVICE_ACCOUNT') {
1212
workshops = await searchAll('workshops', [], [], { orderBy: 'name' });
1313
} else {
1414
// Get workshops that user has access to
@@ -236,9 +236,9 @@ async function getWorkshopStats() {
236236
* Check if user can access workshop
237237
*/
238238
async function canUserAccessWorkshop(userId, workshopId) {
239-
// Admin can access all workshops
239+
// Admin and service accounts can access all workshops
240240
const user = await search('users', 'id', userId);
241-
if (user && user.role === 'ADMIN') {
241+
if (user && (user.role === 'ADMIN' || user.role === 'SERVICE_ACCOUNT')) {
242242
return true;
243243
}
244244

backend/middleware/auth.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ const canAccessWorkshop = async (req, res, next) => {
104104
const { id: workshopId } = req.params;
105105
const userId = req.user.id;
106106

107-
// Admins can access all workshops
108-
if (req.user.role === 'ADMIN') {
107+
// Admins and service accounts can access all workshops
108+
if (req.user.role === 'ADMIN' || req.user.role === 'SERVICE_ACCOUNT') {
109109
return next();
110110
}
111111

@@ -142,8 +142,8 @@ const canAccessInstance = async (req, res, next) => {
142142
const instanceIdToUse = instanceId || id;
143143
const userId = req.user.id;
144144

145-
// Admins can access all instances
146-
if (req.user.role === 'ADMIN') {
145+
// Admins and service accounts can access all instances
146+
if (req.user.role === 'ADMIN' || req.user.role === 'SERVICE_ACCOUNT') {
147147
return next();
148148
}
149149

@@ -183,8 +183,8 @@ const canAccessTeam = async (req, res, next) => {
183183
const { teamId } = req.params;
184184
const userId = req.user.id;
185185

186-
// Admins can access all teams
187-
if (req.user.role === 'ADMIN') {
186+
// Admins and service accounts can access all teams
187+
if (req.user.role === 'ADMIN' || req.user.role === 'SERVICE_ACCOUNT') {
188188
return next();
189189
}
190190

backend/routes/teams.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ router.get('/', authenticateToken, async (req, res) => {
2222
try {
2323
let teams;
2424

25-
// If user is admin, show all teams
26-
if (req.user.role === 'ADMIN') {
25+
// If user is admin or service account, show all teams
26+
if (req.user.role === 'ADMIN' || req.user.role === 'SERVICE_ACCOUNT') {
2727
teams = await searchAll('teams', [], [], { orderBy: 'team_number' });
2828
} else {
2929
// Get teams that user belongs to

backend/routes/workshops.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ router.get('/', authenticateToken, async (req, res) => {
4141
try {
4242
let workshops;
4343

44-
// If user is admin, show all workshops with provider information
45-
if (req.user.role === 'ADMIN') {
44+
// If user is admin or service account, show all workshops with provider information
45+
if (req.user.role === 'ADMIN' || req.user.role === 'SERVICE_ACCOUNT') {
4646
workshops = await executeQuery(`
4747
SELECT w.*, p.name as provider_name
4848
FROM workshops w

0 commit comments

Comments
 (0)