Skip to content

Commit

Permalink
Fix/issue 464 user services (#465)
Browse files Browse the repository at this point in the history
* import Profile

* pass only if the request is internal (param provider is not set)

* include: ['groups', 'profile', 'userBitmap'] to "me" service response

* Update package-lock.json

---------

Co-authored-by: Daniele Guido <[email protected]>
  • Loading branch information
danieleguido and danieleguido authored Dec 3, 2024
1 parent d0576b6 commit d05a957
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/services/me/me.class.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-unused-vars */
import User from '../../models/users.model'
import Profile from '../../models/profiles.model'

const debug = require('debug')('impresso/services:me')
const { BadRequest } = require('@feathersjs/errors')
const SequelizeService = require('../sequelize.service')
const Profile = require('../../models/profiles.model')
const { measureTime } = require('../../util/instruments')

class Service {
Expand All @@ -22,14 +22,23 @@ class Service {
}

async find(params) {
debug('[find] retrieve user from params:', params)
const user = await measureTime(() => this.sequelizeService.get(params.user.id, {}), 'me.find.db.user')
debug('[find] retrieve current user:', user.profile.uid)
debug('[find] retrieve user from params query:', params.query)
const client = this.app.get('sequelizeClient')
const user = await User.sequelize(client).findByPk(params.user.id, {
include: ['groups', 'profile', 'userBitmap'],
})
debug('[find] retrieve current user:', user.profile.uid, user.userBitmap?.bitmap, user.toJSON())

return User.getMe({
user,
const response = User.getMe({
user: {
...user.get(),
bitmap: user.userBitmap?.bitmap,
groups: user.groups?.map(d => d.toJSON()),
},
profile: user.profile,
})
debug('[find] response:', response)
return response
}

async update(id, data, params) {
Expand Down
15 changes: 11 additions & 4 deletions src/services/users/users.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import User from '../../models/users.model'
import Group from '../../models/groups.model'
import Profile from '../../models/profiles.model'
const { BadRequest, NotFound } = require('@feathersjs/errors')
const { BadRequest, NotFound, MethodNotAllowed } = require('@feathersjs/errors')
const shorthash = require('short-hash')
const nanoid = require('nanoid')
const { Op } = require('sequelize')
Expand All @@ -24,7 +24,11 @@ class Service {
}

async get(id, params) {
debug('[get] id:', id)
debug('[get] id:', id, 'provider:', params.provider, 'authenticated:', params.authenticated)
// if it is internal
if (!params.authenticated && params.provider) {
throw new MethodNotAllowed('Not allowed')
}
// if you're staff; otherwise get your own.
const userModel = await this.sequelizeKlass
.scope('isActive')
Expand Down Expand Up @@ -187,9 +191,12 @@ class Service {
}

async find(params) {
debug('find: ', params)
debug('[find] query:', params.query, 'provider:', params.provider)
let uid

// if it is internal
if (params.provider) {
throw new MethodNotAllowed('Not allowed')
}
if (params.sanitized.githubId) {
uid = `github-${params.sanitized.githubId}`
} else if (params.sanitized.email) {
Expand Down

0 comments on commit d05a957

Please sign in to comment.