adapt-authoring-users 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc +14 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +55 -0
- package/.github/ISSUE_TEMPLATE/config.yml +1 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +22 -0
- package/.github/dependabot.yml +11 -0
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/labelled_prs.yml +16 -0
- package/.github/workflows/new.yml +19 -0
- package/adapt-authoring.json +5 -0
- package/conf/config.schema.json +11 -0
- package/errors/errors.json +16 -0
- package/index.js +5 -0
- package/lib/UsersModule.js +112 -0
- package/package.json +18 -0
- package/schema/user.schema.json +36 -0
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules
|
package/.eslintrc
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: Bug Report
|
|
2
|
+
description: File a bug report
|
|
3
|
+
labels: ["bug"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
Thanks for taking the time to fill out this bug report!
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: description
|
|
11
|
+
attributes:
|
|
12
|
+
label: What happened?
|
|
13
|
+
description: Please describe the issue
|
|
14
|
+
validations:
|
|
15
|
+
required: true
|
|
16
|
+
- type: textarea
|
|
17
|
+
id: expected
|
|
18
|
+
attributes:
|
|
19
|
+
label: Expected behaviour
|
|
20
|
+
description: Tell us what should have happened
|
|
21
|
+
- type: textarea
|
|
22
|
+
id: repro-steps
|
|
23
|
+
attributes:
|
|
24
|
+
label: Steps to reproduce
|
|
25
|
+
description: Tell us how to reproduce the issue
|
|
26
|
+
validations:
|
|
27
|
+
required: true
|
|
28
|
+
- type: input
|
|
29
|
+
id: aat-version
|
|
30
|
+
attributes:
|
|
31
|
+
label: Authoring tool version
|
|
32
|
+
description: What version of the Adapt authoring tool are you running?
|
|
33
|
+
validations:
|
|
34
|
+
required: true
|
|
35
|
+
- type: input
|
|
36
|
+
id: fw-version
|
|
37
|
+
attributes:
|
|
38
|
+
label: Framework version
|
|
39
|
+
description: What version of the Adapt framework are you running?
|
|
40
|
+
- type: dropdown
|
|
41
|
+
id: browsers
|
|
42
|
+
attributes:
|
|
43
|
+
label: What browsers are you seeing the problem on?
|
|
44
|
+
multiple: true
|
|
45
|
+
options:
|
|
46
|
+
- Firefox
|
|
47
|
+
- Chrome
|
|
48
|
+
- Safari
|
|
49
|
+
- Microsoft Edge
|
|
50
|
+
- type: textarea
|
|
51
|
+
id: logs
|
|
52
|
+
attributes:
|
|
53
|
+
label: Relevant log output
|
|
54
|
+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
|
55
|
+
render: sh
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blank_issues_enabled: false
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Feature request
|
|
2
|
+
description: Request a new feature
|
|
3
|
+
labels: ["enhancement"]
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
Thanks for taking the time to request a new feature in the Adapt authoring tool! The Adapt team will consider all new feature requests, but unfortunately cannot commit to every one.
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: description
|
|
11
|
+
attributes:
|
|
12
|
+
label: Feature description
|
|
13
|
+
description: Please describe your feature request
|
|
14
|
+
validations:
|
|
15
|
+
required: true
|
|
16
|
+
- type: checkboxes
|
|
17
|
+
id: contribute
|
|
18
|
+
attributes:
|
|
19
|
+
label: Can you work on this feature?
|
|
20
|
+
description: If you are able to commit your own time to work on this feature, it will greatly increase the liklihood of it being implemented by the core dev team. Otherwise, it will be triaged and prioritised alongside the core team's current priorities.
|
|
21
|
+
options:
|
|
22
|
+
- label: I can contribute
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[//]: # (Please title your PR according to eslint commit conventions)
|
|
2
|
+
[//]: # (See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint#eslint-convention for details)
|
|
3
|
+
|
|
4
|
+
[//]: # (Add a link to the original issue)
|
|
5
|
+
|
|
6
|
+
[//]: # (Delete as appropriate)
|
|
7
|
+
### Fix
|
|
8
|
+
* A sentence describing each fix
|
|
9
|
+
|
|
10
|
+
### Update
|
|
11
|
+
* A sentence describing each udpate
|
|
12
|
+
|
|
13
|
+
### New
|
|
14
|
+
* A sentence describing each new feature
|
|
15
|
+
|
|
16
|
+
### Breaking
|
|
17
|
+
* A sentence describing each breaking change
|
|
18
|
+
|
|
19
|
+
[//]: # (List appropriate steps for testing if needed)
|
|
20
|
+
### Testing
|
|
21
|
+
1. Steps for testing
|
|
22
|
+
|
|
23
|
+
[//]: # (Mention any other dependencies)
|
|
24
|
+
|
|
25
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Add labelled PRs to project
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [ labeled ]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
add-to-project:
|
|
9
|
+
if: ${{ github.event.label.name == 'dependencies' }}
|
|
10
|
+
name: Add to main project
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/add-to-project@v0.1.0
|
|
14
|
+
with:
|
|
15
|
+
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
16
|
+
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Add to main project
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issues:
|
|
5
|
+
types:
|
|
6
|
+
- opened
|
|
7
|
+
pull_request:
|
|
8
|
+
types:
|
|
9
|
+
- opened
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
add-to-project:
|
|
13
|
+
name: Add to main project
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/add-to-project@v0.1.0
|
|
17
|
+
with:
|
|
18
|
+
project-url: https://github.com/orgs/adapt-security/projects/5
|
|
19
|
+
github-token: ${{ secrets.PROJECTS_SECRET }}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"DUPL_USER": {
|
|
3
|
+
"data": {
|
|
4
|
+
"email": "Email address of the user"
|
|
5
|
+
},
|
|
6
|
+
"description": "A user already exists with the passed email address",
|
|
7
|
+
"statusCode": 400
|
|
8
|
+
},
|
|
9
|
+
"USER_SELF_DELETE_ILLEGAL": {
|
|
10
|
+
"data": {
|
|
11
|
+
"id": "_id of the user"
|
|
12
|
+
},
|
|
13
|
+
"description": "You cannot delete your own user account",
|
|
14
|
+
"statusCode": 400
|
|
15
|
+
}
|
|
16
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import AbstractApiModule from 'adapt-authoring-api'
|
|
2
|
+
/**
|
|
3
|
+
* Module which handles user management
|
|
4
|
+
* @memberof users
|
|
5
|
+
* @extends {AbstractApiModule}
|
|
6
|
+
*/
|
|
7
|
+
class UsersModule extends AbstractApiModule {
|
|
8
|
+
/** @override */
|
|
9
|
+
async setValues () {
|
|
10
|
+
/** @ignore */ this.root = 'users'
|
|
11
|
+
/** @ignore */ this.schemaName = 'user'
|
|
12
|
+
/** @ignore */ this.collectionName = 'users'
|
|
13
|
+
|
|
14
|
+
this.useDefaultRouteConfig()
|
|
15
|
+
// remove POST / route
|
|
16
|
+
delete this.routes.find(r => r.route === '/').handlers.post
|
|
17
|
+
|
|
18
|
+
const desc = method => `This endpoint is shorthand for \`${method}\` \`/api/${this.root}/:_id\`, see the documentation for that endpoint for more details`
|
|
19
|
+
|
|
20
|
+
this.routes = [{
|
|
21
|
+
route: '/me',
|
|
22
|
+
modifiers: ['put', 'patch'],
|
|
23
|
+
handlers: { get: this.requestHandler(), put: this.requestHandler(), patch: this.requestHandler() },
|
|
24
|
+
permissions: { get: ['read:me'], put: ['write:me'], patch: ['write:me'] },
|
|
25
|
+
meta: {
|
|
26
|
+
get: { summary: 'Retrieve your own user data', description: desc('GET') },
|
|
27
|
+
put: { summary: 'Replace your own user data', description: desc('PUT') },
|
|
28
|
+
patch: { summary: 'Update your own user data', description: desc('PATCH') }
|
|
29
|
+
}
|
|
30
|
+
}, ...this.routes]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initialises the module
|
|
35
|
+
* @return {Promise}
|
|
36
|
+
*/
|
|
37
|
+
async init () {
|
|
38
|
+
await super.init()
|
|
39
|
+
const [mongodb, server] = await this.app.waitForModule('mongodb', 'server')
|
|
40
|
+
await mongodb.setIndex(this.collectionName, 'email', { unique: true })
|
|
41
|
+
|
|
42
|
+
server.api.addHandlerMiddleware(this.updateAccess.bind(this))
|
|
43
|
+
|
|
44
|
+
this.requestHook.tap(this.onRequest.bind(this))
|
|
45
|
+
|
|
46
|
+
if (this.getConfig('forceLowerCaseEmail')) {
|
|
47
|
+
this.preInsertHook.tap(this.forceLowerCaseEmail)
|
|
48
|
+
this.preUpdateHook.tap(this.forceLowerCaseEmail)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
forceLowerCaseEmail (data) {
|
|
53
|
+
if (data.email) data.email = data.email.toLowerCase()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @override */
|
|
57
|
+
async processRequestMiddleware (req, res, next) {
|
|
58
|
+
super.processRequestMiddleware(req, res, () => {
|
|
59
|
+
req.apiData.schemaName = req.auth.userSchemaName
|
|
60
|
+
next()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Updates the user access timestamp
|
|
66
|
+
* @param {external:ExpressRequest} req
|
|
67
|
+
* @param {external:ExpressResponse} res
|
|
68
|
+
* @param {Function} next
|
|
69
|
+
*/
|
|
70
|
+
updateAccess (req, res, next) {
|
|
71
|
+
const _id = req.auth?.user?._id
|
|
72
|
+
if (_id) { // note we only log any errors, as it's not necessarily a problem
|
|
73
|
+
this.update({ _id }, { lastAccess: new Date().toISOString() })
|
|
74
|
+
.catch(e => this.log('warn', `Failed to update user lastAccess, ${e}`))
|
|
75
|
+
}
|
|
76
|
+
next()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Adds the current user _id to an incoming request to API
|
|
81
|
+
* @param {external:ExpressRequest} req
|
|
82
|
+
*/
|
|
83
|
+
async onRequest (req) {
|
|
84
|
+
if (req.apiData.config.route === '/me') {
|
|
85
|
+
req.params._id = req.apiData.query._id = req.auth.user._id
|
|
86
|
+
// users shouldn't be able to disable themselves
|
|
87
|
+
if (req.apiData.data.isEnabled) delete req.apiData.data.isEnabled
|
|
88
|
+
}
|
|
89
|
+
if (req.method === 'DELETE' && (req.apiData.query._id === req.auth.user._id)) {
|
|
90
|
+
throw this.app.errors.USER_SELF_DELETE_ILLEGAL
|
|
91
|
+
.setData({ id: req.user._id })
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** @override */
|
|
96
|
+
async insert (data, options, mongoOptions) {
|
|
97
|
+
try {
|
|
98
|
+
return await super.insert(data, options, mongoOptions)
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (e.code === this.app.errors.MONGO_DUPL_INDEX) throw this.app.errors.DUPL_USER.setData({ email: data.email })
|
|
101
|
+
throw e
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @override */
|
|
106
|
+
async find (query, options = {}, mongoOptions = {}) {
|
|
107
|
+
query.email = this.getConfig('forceLowerCaseEmail') ? query.email?.toLowerCase() : undefined
|
|
108
|
+
return super.find(query, options, mongoOptions)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default UsersModule
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "adapt-authoring-users",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Module for managing users",
|
|
5
|
+
"homepage": "https://github.com/adapt-security/adapt-authoring-users",
|
|
6
|
+
"license": "GPL-3.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"repository": "github:adapt-security/adapt-authoring-users",
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"adapt-authoring-api": "github:adapt-security/adapt-authoring-api",
|
|
12
|
+
"adapt-authoring-core": "github:adapt-security/adapt-authoring-core"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"eslint": "^9.12.0",
|
|
16
|
+
"standard": "^17.1.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$anchor": "user",
|
|
4
|
+
"description": "A system user",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"email": {
|
|
8
|
+
"description": "Email address for the user",
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"firstName": {
|
|
12
|
+
"description": "First name of the user",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"default": "Adapt"
|
|
15
|
+
},
|
|
16
|
+
"lastName": {
|
|
17
|
+
"description": "Last name of the user",
|
|
18
|
+
"type": "string",
|
|
19
|
+
"default": "User"
|
|
20
|
+
},
|
|
21
|
+
"isEnabled": {
|
|
22
|
+
"description": "Whether the user is able to access the system",
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"isReadOnly": true,
|
|
25
|
+
"default": true
|
|
26
|
+
},
|
|
27
|
+
"lastAccess": {
|
|
28
|
+
"description": "Timestamp of the last access",
|
|
29
|
+
"type": "string",
|
|
30
|
+
"format": "date-time",
|
|
31
|
+
"isReadOnly": true,
|
|
32
|
+
"isDate": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"required": ["email"]
|
|
36
|
+
}
|