Skip to content

Commit 58e6233

Browse files
committed
Merge branch 'master' into style-manager
2 parents 5b99c90 + 25414dd commit 58e6233

File tree

192 files changed

+4202
-5516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+4202
-5516
lines changed

core/api/authentication.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import makeDebug from 'debug'
22
import _ from 'lodash'
3+
import qs from 'qs'
34
import 'winston-daily-rotate-file'
45
// import { RateLimiter } from 'limiter'
56
import HttpLimiter from 'express-rate-limit'
@@ -32,6 +33,23 @@ export class Authentication extends AuthenticationService {
3233
}
3334

3435
export class AuthenticationProviderStrategy extends OAuthStrategy {
36+
setAuthentication (auth) {
37+
super.setAuthentication(auth)
38+
const authConfig = this.authentication.configuration
39+
const { oauth } = authConfig
40+
// Single logout supported ?
41+
const { logout_url: logoutUrl, post_logout_url: postLogoutUrl, key } = this.configuration
42+
if (logoutUrl && key) {
43+
// Cannot use oauth/:provider/logout route as oauth/:provider is already intercepted by feathers and this causes an error
44+
this.app.get(`/oauth-logout/${this.name}`, (req, res) => {
45+
return res.redirect(logoutUrl + '?' + qs.stringify({
46+
post_logout_redirect_uri: postLogoutUrl || oauth.redirect,
47+
client_id: key
48+
}))
49+
})
50+
}
51+
}
52+
3553
async getEntityData (profile, entity) {
3654
const createEntity = _.isNil(entity)
3755
// Add provider Id

core/api/hooks/hooks.authentication.js

-58
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,6 @@ const { discard } = common
88
// Make it more easy to access
99
export const hashPassword = local.hooks.hashPassword
1010

11-
export async function verifyGuest (hook) {
12-
if (hook.type !== 'after') {
13-
throw new Error('The \'verifyGuest\' hook should only be used as a \'after\' hook.')
14-
}
15-
const app = hook.app
16-
const user = hook.result.user
17-
if (!user) return hook
18-
debug('verifyGuest hook called on ', user._id)
19-
20-
// Check whether the user has been invited. If not, nothing to do
21-
if (!user.sponsor) {
22-
debug('Logged user is not a guest')
23-
return hook
24-
}
25-
26-
// Check whether has been already verified. If yes, nothing to do
27-
if (user.isVerified) {
28-
debug('Logged guest is already verified')
29-
return hook
30-
}
31-
32-
// The user is a guest and need to be verified
33-
debug('Verifying logged guest')
34-
const userService = app.getService('users')
35-
await userService.patch(user._id, { isVerified: true })
36-
37-
return hook
38-
}
39-
40-
export async function consentGuest (hook) {
41-
if (hook.type !== 'after') {
42-
throw new Error('The \'consentGuest\' hook should only be used as a \'after\' hook.')
43-
}
44-
const app = hook.app
45-
const user = hook.result.user
46-
if (!user) return hook
47-
debug('consentGuest hook called on ', user._id)
48-
49-
// Check whether the user has been invited. If not, nothing to do
50-
if (!user.sponsor) {
51-
debug('Logged user is not a guest')
52-
return hook
53-
}
54-
55-
// Check whether consent has been already checked. If yes, nothing to do
56-
if (user.consentTerms) {
57-
debug('Logged guest is already verified')
58-
return hook
59-
}
60-
61-
// The user is a guest and need to be consent
62-
debug('Consenting logged guest')
63-
const userService = app.getService('users')
64-
await userService.patch(user._id, { consentTerms: true, expireAt: null })
65-
66-
return hook
67-
}
68-
6911
export function discardAuthenticationProviders (hook) {
7012
const providers = hook.app.authenticationProviders || []
7113

core/api/hooks/hooks.authorisations.js

-96
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
hasServiceAbilities, hasResourceAbilities, getQueryForAbilities,
99
Roles, RoleNames, countSubjectsForResource
1010
} from '../../common/permissions.js'
11-
import { isTagEqual } from '../utils.js'
1211

1312
const { getItems, replaceItems } = common
1413
const { Forbidden } = errors
@@ -289,98 +288,3 @@ export function updateAbilities (options = {}) {
289288
}
290289
}
291290

292-
export function preventRemovingLastOwner (resourceScope) {
293-
return async function (hook) {
294-
// By pass check ?
295-
if (hook.params.force) return hook
296-
const params = hook.params
297-
const data = hook.data || {}
298-
const query = params.query || {}
299-
const scope = data.scope || query.scope
300-
const grantedPermissions = data.permissions || query.permissions
301-
const grantedRole = (grantedPermissions ? Roles[grantedPermissions] : undefined)
302-
const resource = hook.params.resource
303-
const subjects = hook.params.subjects
304-
const subjectService = hook.params.subjectsService
305-
// On create check if we try to downgrade permissions otherwise let pass through
306-
if (!_.isUndefined(grantedRole) && (grantedRole === Roles.owner)) return hook
307-
308-
if ((scope === resourceScope) && resource && resource._id) {
309-
// Count existing owners
310-
const owners = await countSubjectsForResource(subjectService, resourceScope, resource._id, Roles.owner)
311-
// Now count owners we change/remove permissions on
312-
const removedOwners = subjects.reduce((count, subject) => {
313-
const resources = _.get(subject, resourceScope, [])
314-
const ownedResource = _.find(resources, { _id: resource._id, permissions: RoleNames[Roles.owner] })
315-
return (ownedResource ? count + 1 : count)
316-
}, 0)
317-
// If none remains stop
318-
if (removedOwners >= owners.total) {
319-
debug('Cannot remove the last owner of resource ', resource)
320-
const resourceName = resource.name ? resource.name : resource._id.toString()
321-
throw new Forbidden('You are not allowed to remove the last owner of resource ' + resourceName, {
322-
translation: {
323-
key: 'CANNOT_REMOVE_LAST_OWNER',
324-
params: { resource: resourceName }
325-
}
326-
})
327-
}
328-
}
329-
return hook
330-
}
331-
}
332-
333-
export async function removeOrganisationGroupsAuthorisations (hook) {
334-
const app = hook.app
335-
const authorisationService = app.getService('authorisations')
336-
const org = hook.params.resource
337-
const user = hook.params.user
338-
// Unset membership for the all org groups
339-
const orgGroupService = app.getService('groups', org)
340-
const groups = await orgGroupService.find({ paginate: false })
341-
await Promise.all(groups.map(group => {
342-
// Unset membership on group for the all org users
343-
return authorisationService.remove(group._id.toString(), {
344-
query: {
345-
scope: 'groups'
346-
},
347-
user,
348-
force: hook.params.force,
349-
// Because we already have resource set it as objects to avoid populating
350-
// Moreover used as an after hook the resource might not already exist anymore
351-
subjects: hook.params.subjects,
352-
subjectsService: hook.params.subjectsService,
353-
resource: group,
354-
resourcesService: orgGroupService
355-
})
356-
}))
357-
debug('Authorisations unset on groups for organisation ' + org._id)
358-
return hook
359-
}
360-
361-
export async function removeOrganisationTagsAuthorisations (hook) {
362-
const app = hook.app
363-
const org = hook.params.resource
364-
const subjectService = hook.params.subjectsService
365-
const orgTagsService = app.getService('tags', org)
366-
const subjects = hook.params.subjects || []
367-
if (subjects.length === 0) return hook
368-
// Retrieve org tags
369-
const orgTags = await orgTagsService.find({ paginate: false })
370-
const promises = []
371-
subjects.forEach(subject => {
372-
const tags = subject.tags || []
373-
// Find tags from org
374-
const fromOrg = _.intersectionWith(tags, orgTags, isTagEqual)
375-
// Clear removed tags
376-
const notFromOrg = _.differenceWith(tags, orgTags, isTagEqual)
377-
// Update subject if required
378-
if (fromOrg.length > 0) {
379-
promises.push(subjectService.patch(subject._id.toString(), { tags: notFromOrg }))
380-
}
381-
})
382-
// Perform subject updates in parallel
383-
await Promise.all(promises)
384-
debug(`Tags unset on ${promises.length} subjects for organisation ` + org._id)
385-
return hook
386-
}

core/api/hooks/hooks.groups.js

-48
This file was deleted.

0 commit comments

Comments
 (0)