Skip to content

Commit

Permalink
fix: Zombie organisation services (closes #420)
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed May 25, 2023
1 parent b5dbe66 commit c3c7388
Show file tree
Hide file tree
Showing 47 changed files with 639 additions and 590 deletions.
24 changes: 24 additions & 0 deletions api/src/hooks/hooks.organisations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import makeDebug from 'debug'

const debug = makeDebug('aktnmap:organisations:hooks')

export function removeOrganisationAlerts (hook) {
if (hook.type !== 'after') {
throw new Error('The \'removeOrganisationAlerts\' hook should only be used as a \'after\' hook.')
}

const app = hook.app
const orgAlertService = app.getService('alerts', hook.result)
return orgAlertService.find({ paginate: false })
.then(alerts => {
return Promise.all(alerts.map(group => {
return orgAlertService.remove(group._id.toString(), {
user: hook.params.user
})
}))
})
.then(alerts => {
debug('Removed alerts for organisation ' + hook.result._id)
return hook
})
}
1 change: 1 addition & 0 deletions api/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './hooks.event-logs.js'
export * from './hooks.event-templates.js'
export * from './hooks.devices.js'
export * from './hooks.archiving.js'
export * from './hooks.organisations.js'
export * from './hooks.plans.js'

export function addCreatorAsCoordinator (hook) {
Expand Down
40 changes: 24 additions & 16 deletions api/src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export async function createEventService (options = {}) {
}, options))
}

export function removeEventService (options) {
// TODO
export function removeEventService (options = {}) {
const app = this
return app.removeService(app.getService('events', options.context))
}

export async function createEventTemplateService (options = {}) {
Expand All @@ -42,8 +43,9 @@ export async function createEventTemplateService (options = {}) {
}, options))
}

export function removeEventTemplateService (options) {
// TODO
export function removeEventTemplateService (options = {}) {
const app = this
return app.removeService(app.getService('event-templates', options.context))
}

export async function createEventLogService (options = {}) {
Expand All @@ -57,8 +59,9 @@ export async function createEventLogService (options = {}) {
}, options))
}

export function removeEventLogService (options) {
// TODO
export function removeEventLogService (options = {}) {
const app = this
return app.removeService(app.getService('event-logs', options.context))
}

export async function createArchivedEventService (options = {}) {
Expand All @@ -72,8 +75,9 @@ export async function createArchivedEventService (options = {}) {
}, options))
}

export function removeArchivedEventService (options) {
// TODO
export function removeArchivedEventService (options = {}) {
const app = this
return app.removeService(app.getService('archived-events', options.context))
}

export async function createArchivedEventLogService (options = {}) {
Expand All @@ -87,8 +91,9 @@ export async function createArchivedEventLogService (options = {}) {
}, options))
}

export function removeArchivedEventLogService (options) {
// TODO
export function removeArchivedEventLogService (options = {}) {
const app = this
return app.removeService(app.getService('archived-event-logs', options.context))
}

export async function createPlanTemplateService (options = {}) {
Expand All @@ -101,8 +106,9 @@ export async function createPlanTemplateService (options = {}) {
}, options))
}

export function removePlanTemplateService (options) {
// TODO
export function removePlanTemplateService (options = {}) {
const app = this
return app.removeService(app.getService('plan-templates', options.context))
}

export async function createPlanService (options = {}) {
Expand All @@ -115,8 +121,9 @@ export async function createPlanService (options = {}) {
}, options))
}

export function removePlanService (options) {
// TODO
export function removePlanService (options = {}) {
const app = this
return app.removeService(app.getService('plans', options.context))
}

export async function createArchivedPlanService (options = {}) {
Expand All @@ -130,8 +137,9 @@ export async function createArchivedPlanService (options = {}) {
}, options))
}

export function removeArchivedPlanService (options) {
// TODO
export function removeArchivedPlanService (options = {}) {
const app = this
return app.removeService(app.getService('archived-plans', options.context))
}

export async function createOrganisationServices (organisation, db) {
Expand Down
4 changes: 3 additions & 1 deletion api/src/services/organisations/organisations.hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'lodash'
import commonHooks from 'feathers-hooks-common'
import { hooks as coreHooks } from '@kalisio/kdk/core.api.js'
import { checkOrganisationsQuotas, checkSubscriptionQuotas, subscribeDefaultPlan, removeBilling } from '../../hooks/index.js'
import { checkOrganisationsQuotas, checkSubscriptionQuotas, subscribeDefaultPlan,
removeBilling, removeOrganisationAlerts } from '../../hooks/index.js'

export default {
before: {
Expand Down Expand Up @@ -30,6 +31,7 @@ export default {
remove: [
coreHooks.setAsDeleted,
removeBilling,
removeOrganisationAlerts,
coreHooks.removeOrganisationGroups,
coreHooks.removeOrganisationTags,
coreHooks.removeOrganisationAuthorisations,
Expand Down
2 changes: 2 additions & 0 deletions api/test/billing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe('billing', () => {
expect(subscriptionService).toExist()
await new Promise(resolve => server.once('listening', () => resolve()))
})
// Let enough time to process
.timeout(5000)

it('creates a test user', async () => {
const user = await userService.create({ email: '[email protected]', name: 'test-user' }, { checkAuthorisation: true })
Expand Down
11 changes: 11 additions & 0 deletions api/test/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ describe('events', () => {
await orgService.remove(orgObject._id, { user: orgManagerObject, checkAuthorisation: true })
const orgs = await orgService.find({ query: { name: 'test-org' }, user: orgManagerObject, checkAuthorisation: true })
expect(orgs.data.length === 0).beTrue()

eventService = server.app.getService(`${orgObject._id.toString()}/events`)
expect(eventService).beNull()
archivedEventService = server.app.getService(`${orgObject._id.toString()}/archived-events`)
expect(archivedEventService).beNull()
eventTemplateService = server.app.getService(`${orgObject._id.toString()}/event-templates`)
expect(eventTemplateService).beNull()
eventLogService = server.app.getService(`${orgObject._id.toString()}/event-logs`)
expect(eventLogService).beNull()
archivedEventLogService = server.app.getService(`${orgObject._id.toString()}/archived-event-logs`)
expect(archivedEventLogService).beNull()
})
// Let enough time to process
.timeout(5000)
Expand Down
19 changes: 12 additions & 7 deletions api/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { createServer, runServer } from '../src/server.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

describe('aktnmap', () => {
let server, expressServer, userService, userObject, memberObject, orgService, orgObject, authorisationService, devicesService, pusherService, billingService, sns,
mailerService, memberService, tagService, tagObject, memberTagObject, groupService, groupObject, gmailClient, gmailUser,
subscriptionObject, client, password
let server, expressServer, userService, userObject, memberObject, orgService, orgObject,
authorisationService, devicesService, pusherService, billingService, sns, mailerService,
memberService, tagService, tagObject, memberTagObject, groupService, groupObject,
gmailClient, gmailUser, subscriptionObject, client, password
const now = new Date()
const logFilePath = path.join(__dirname, 'logs', 'aktnmap-' + now.toISOString().slice(0, 10) + '.log')
const device = {
Expand Down Expand Up @@ -85,9 +86,7 @@ describe('aktnmap', () => {
const gmailApiConfig = {
user: process.env.GMAIL_API_USER,
clientEmail: process.env.GMAIL_API_CLIENT_EMAIL,
// The private key file is set as an environment variable containing \n
// So we need to parse it such as if it came from a JSON file
privateKey: JSON.parse('{ "key": "' + process.env.GMAIL_API_PRIVATE_KEY + '" }').key
privateKey: process.env.GMAIL_API_PRIVATE_KEY
}
gmailUser = gmailApiConfig.user
gmailClient = await createGmailClient(gmailApiConfig)
Expand Down Expand Up @@ -755,7 +754,7 @@ describe('aktnmap', () => {
return userService.get(userObject._id, { user: userObject, checkAuthorisation: true })
})
.then(user => {
// Update user with his new permissions
// Update user with his new permissions
userObject = user
expect(userObject.organisations).toExist()
expect(userObject.organisations.length === 0).beTrue()
Expand All @@ -765,6 +764,12 @@ describe('aktnmap', () => {
})
.then(orgs => {
expect(orgs.data.length === 0).beTrue()
memberService = server.app.getService(`${orgObject._id.toString()}/members`)
expect(memberService).beNull()
tagService = server.app.getService(`${orgObject._id.toString()}/tags`)
expect(tagService).beNull()
groupService = server.app.getService(`${orgObject._id.toString()}/groups`)
expect(groupService).beNull()
})
const events = new Promise((resolve, reject) => {
// This should unsubscribe device to org topic
Expand Down
10 changes: 5 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<!-- Don't drop "q-app" class -->
<div id="q-app">
<!-- Ajax bar -->
<q-ajax-bar
ref="bar"
position="bottom"
size="8px"
color="primary"
<q-ajax-bar
ref="bar"
position="bottom"
size="8px"
color="primary"
:delay="250">
</q-ajax-bar>
<!-- Router view -->
Expand Down
12 changes: 6 additions & 6 deletions src/boot/kdk.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import _ from 'lodash'
import config from 'config'
import { Notify } from 'quasar'
import { Notify, Dialog } from 'quasar'
import appHooks from '../app.hooks'
import services from '../services'
import { initializeApi, i18n, utils as kdkCoreUtils, Store, Layout, Events, Theme, beforeGuard, authenticationGuard } from '@kalisio/kdk/core.client'
import { initializeApi, i18n, utils as kdkCoreUtils, Store, Layout, Events, beforeGuard, authenticationGuard } from '@kalisio/kdk/core.client'
import { Geolocation } from '@kalisio/kdk/map.client.map'

/*function updateThemeColors () {
/* function updateThemeColors () {
const theme = config.theme
// Default theme override
if (theme) Theme.apply(theme)
}*/
} */

export default async ({ app }) => {
// Required to make injections reactively linked to the provider
Expand Down Expand Up @@ -73,7 +73,7 @@ export default async ({ app }) => {
app.component('KGrid', await kdkCoreUtils.loadComponent('collection/KGrid'))
app.component('KBoard', await kdkCoreUtils.loadComponent('collection/KBoard'))
app.component('KHistory', await kdkCoreUtils.loadComponent('collection/KHistory'))
app.component('KItem', await kdkCoreUtils.loadComponent('collection/KItem'))
app.component('KItem', await kdkCoreUtils.loadComponent('collection/KItem'))
app.component('KCard', await kdkCoreUtils.loadComponent('collection/KCard'))
app.component('KCardSection', await kdkCoreUtils.loadComponent('collection/KCardSection'))
app.component('KMediaBrowser', await kdkCoreUtils.loadComponent('media/KMediaBrowser'))
Expand All @@ -96,7 +96,7 @@ export default async ({ app }) => {
// Add global guard
beforeGuard.registerGuard(authenticationGuard)

//updateThemeColors()
// updateThemeColors()

api.on('authenticated', (data) => {
// Store API gateway token if any
Expand Down
32 changes: 16 additions & 16 deletions src/components/AlertEditor.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<KModal
<KModal
:title="$t('CatalogActivity.CREATE_ALERT_TITLE')"
:buttons="buttons"
>
<AlertForm
>
<AlertForm
:ref="onFormReferenceCreated"
:layer="layer"
:feature="feature"
:layer="layer"
:feature="feature"
:forecastModel="forecastModel"
@form-ready="onFormReady"
/>
Expand All @@ -26,21 +26,21 @@ export default {
kdkCoreMixins.baseModal
],
props: {
layer: {
type: Object,
default: () => null
layer: {
type: Object,
default: () => null
},
feature: {
type: Object,
default: () => null
feature: {
type: Object,
default: () => null
},
forecastModel: {
type: Object,
default: () => null
forecastModel: {
type: Object,
default: () => null
}
},
computed: {
buttons () {
buttons () {
return [
{ id: 'cancel-button', label: 'CANCEL', renderer: 'form-button', outline: true, handler: () => this.closeModal() },
{ id: 'apply-button', label: 'DONE', renderer: 'form-button', handler: () => this.apply() }
Expand Down Expand Up @@ -75,4 +75,4 @@ export default {
}
}
}
</script>
</script>
37 changes: 21 additions & 16 deletions src/components/AlertForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { QSlider, QRange } from 'quasar'
export default {
components: {
QSlider,
QSlider,
QRange,
KItemField: kdkCoreUtils.loadComponent('form/KItemField'),
KToggleField: kdkCoreUtils.loadComponent('form/KToggleField')
Expand Down Expand Up @@ -182,16 +182,18 @@ export default {
return options
},
getOperators (variable) {
return this.isRange(variable) ? [{
label: this.$i18n.t('AlertForm.RANGE'),
value: '$range'
}] : [{
label: this.$i18n.t('AlertForm.GREATER_THAN'),
value: '$gte'
}, {
label: this.$i18n.t('AlertForm.LOWER_THAN'),
value: '$lte'
}]
return this.isRange(variable)
? [{
label: this.$i18n.t('AlertForm.RANGE'),
value: '$range'
}]
: [{
label: this.$i18n.t('AlertForm.GREATER_THAN'),
value: '$gte'
}, {
label: this.$i18n.t('AlertForm.LOWER_THAN'),
value: '$lte'
}]
},
isRange (variable) {
const unitsWithRange = ['deg']
Expand All @@ -210,10 +212,12 @@ export default {
return {
isActive: false,
operator: this.isRange(variable) ? '$range' : '$gte',
threshold: this.isRange(variable) ? {
min: Math.ceil((max - min) * 0.25 / step) * step, // Quartiles rounded to nearest step
max: Math.ceil((max - min) * 0.75 / step) * step
} : Math.ceil((max - min) * 0.5 / step) * step, // Mean value rounded to nearest step
threshold: this.isRange(variable)
? {
min: Math.ceil((max - min) * 0.25 / step) * step, // Quartiles rounded to nearest step
max: Math.ceil((max - min) * 0.75 / step) * step
}
: Math.ceil((max - min) * 0.5 / step) * step, // Mean value rounded to nearest step
min,
max,
step
Expand Down Expand Up @@ -342,7 +346,8 @@ export default {
// Add reference to feature service whenever required
if (this.layer.service) {
_.set(values, 'feature', this.layer.featureId
? _.get(this.feature, 'properties.' + this.layer.featureId) : this.feature._id)
? _.get(this.feature, 'properties.' + this.layer.featureId)
: this.feature._id)
}
// Setup style if any provided, except if templated as it would require
// a complex mapping with the underlying feature
Expand Down
Loading

0 comments on commit c3c7388

Please sign in to comment.