adapt-authoring-tags 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/artillery.yml +16 -0
- package/index.js +5 -0
- package/lib/TagsModule.js +166 -0
- package/package.json +19 -0
- package/schema/tag.schema.json +13 -0
- package/schema/tags.schema.json +23 -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 }}
|
package/artillery.yml
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import AbstractApiModule from 'adapt-authoring-api'
|
|
2
|
+
/**
|
|
3
|
+
* Module which handles tagging
|
|
4
|
+
* @memberof tags
|
|
5
|
+
* @extends {AbstractApiModule}
|
|
6
|
+
*/
|
|
7
|
+
class TagsModule extends AbstractApiModule {
|
|
8
|
+
/** @override */
|
|
9
|
+
async init () {
|
|
10
|
+
await super.init()
|
|
11
|
+
const jsonschema = await this.app.waitForModule('jsonschema')
|
|
12
|
+
jsonschema.registerSchemasHook.tap(this.registerSchemas.bind(this))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @override */
|
|
16
|
+
async setValues () {
|
|
17
|
+
/** @ignore */ this.root = 'tags'
|
|
18
|
+
/** @ignore */ this.schemaName = 'tag'
|
|
19
|
+
/** @ignore */ this.schemaExtensionName = 'tags'
|
|
20
|
+
/** @ignore */ this.collectionName = 'tags'
|
|
21
|
+
/**
|
|
22
|
+
* Module registered for tags
|
|
23
|
+
* @type {Array<AbstractApiModule>}
|
|
24
|
+
*/
|
|
25
|
+
this.modules = []
|
|
26
|
+
|
|
27
|
+
this.useDefaultRouteConfig()
|
|
28
|
+
|
|
29
|
+
this.routes = [{
|
|
30
|
+
route: '/autocomplete',
|
|
31
|
+
handlers: { get: this.autocompleteHandler.bind(this) },
|
|
32
|
+
permissions: { get: ['read:content'] },
|
|
33
|
+
meta: {
|
|
34
|
+
get: {
|
|
35
|
+
summary: 'Retrieve tags for UI autocomplete',
|
|
36
|
+
description: 'A streamlined query API to allow searching of tag data.',
|
|
37
|
+
parameters: [{ name: 'term', in: 'query', description: 'Search term', required: true }],
|
|
38
|
+
responses: {
|
|
39
|
+
200: {
|
|
40
|
+
content: {
|
|
41
|
+
'application/json': {
|
|
42
|
+
schema: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
_id: { type: 'string' },
|
|
48
|
+
title: { type: 'string' },
|
|
49
|
+
value: { type: 'string' }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
route: '/transfer/:_id',
|
|
61
|
+
handlers: { post: this.transferHandler.bind(this) },
|
|
62
|
+
permissions: { post: ['write:content'] },
|
|
63
|
+
modifying: false,
|
|
64
|
+
meta: {
|
|
65
|
+
post: {
|
|
66
|
+
summary: 'Transfer tag',
|
|
67
|
+
description: 'Transfers all items using one tag for another.'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, ...this.routes]
|
|
71
|
+
// make title unique
|
|
72
|
+
const mongodb = await this.app.waitForModule('mongodb')
|
|
73
|
+
return mongodb.setIndex(this.collectionName, 'title', { unique: true })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Registers a module for use with this plugin
|
|
78
|
+
* @param {AbstractApiModule} mod
|
|
79
|
+
*/
|
|
80
|
+
async registerModule (mod) {
|
|
81
|
+
if (!mod.schemaName) {
|
|
82
|
+
return this.log('warn', 'cannot register module, module doesn\'t define a schemaName')
|
|
83
|
+
}
|
|
84
|
+
await this.registerSchemas()
|
|
85
|
+
|
|
86
|
+
this.log('debug', `registered ${mod.name} for use with tags`)
|
|
87
|
+
this.modules.push(mod)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Registers module schemas
|
|
92
|
+
*/
|
|
93
|
+
async registerSchemas () {
|
|
94
|
+
const jsonschema = await this.app.waitForModule('jsonschema')
|
|
95
|
+
this.modules.forEach(mod => {
|
|
96
|
+
try {
|
|
97
|
+
jsonschema.extendSchema(mod.schemaName, this.schemaExtensionName)
|
|
98
|
+
} catch(e) {}
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* A handler for autocompletion of tags
|
|
104
|
+
* @param {external:ExpressRequest} req
|
|
105
|
+
* @param {external:ExpressResponse} res
|
|
106
|
+
* @param {Function} next
|
|
107
|
+
*/
|
|
108
|
+
async autocompleteHandler (req, res, next) {
|
|
109
|
+
res.json((await this.find({ title: { $regex: `^${req.apiData.query.term}` } })).map(m => {
|
|
110
|
+
return {
|
|
111
|
+
_id: m._id,
|
|
112
|
+
title: m.title,
|
|
113
|
+
value: m.title
|
|
114
|
+
}
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Transfers items using a source tag to a different destination tag
|
|
120
|
+
* @param {external:ExpressRequest} req
|
|
121
|
+
* @param {external:ExpressResponse} res
|
|
122
|
+
* @param {Function} next
|
|
123
|
+
*/
|
|
124
|
+
async transferHandler (req, res, next) {
|
|
125
|
+
const sourceId = req.apiData.query._id
|
|
126
|
+
const destId = req.apiData.data.destId
|
|
127
|
+
try {
|
|
128
|
+
await Promise.all(this.modules.map(async m => {
|
|
129
|
+
try {
|
|
130
|
+
await m.updateMany({ tags: sourceId }, { $push: { tags: destId } }, { rawUpdate: true })
|
|
131
|
+
if(req.apiData.query.deleteSourceTag !== 'true') await m.updateMany({ tags: sourceId }, { $pull: { tags: sourceId } }, { rawUpdate: true })
|
|
132
|
+
} catch (e) {
|
|
133
|
+
this.log('warn', `Failed to transfer tag, ${e}`)
|
|
134
|
+
}
|
|
135
|
+
}))
|
|
136
|
+
if(req.apiData.query.deleteSourceTag === 'true') {
|
|
137
|
+
await this.delete({ _id: sourceId })
|
|
138
|
+
}
|
|
139
|
+
} catch(e) {
|
|
140
|
+
next(e)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @override */
|
|
145
|
+
async insert (...args) {
|
|
146
|
+
// allow attempts to create tags that already exist
|
|
147
|
+
const [tag] = await this.find(...args)
|
|
148
|
+
if (tag) return tag
|
|
149
|
+
return super.insert(...args)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @override */
|
|
153
|
+
async delete (...args) {
|
|
154
|
+
const data = await super.delete(...args)
|
|
155
|
+
await Promise.all(this.modules.map(async m => {
|
|
156
|
+
try {
|
|
157
|
+
await m.updateMany({ tags: data._id }, { $pull: { tags: data._id } }, { rawUpdate: true })
|
|
158
|
+
} catch (e) {
|
|
159
|
+
this.log('warn', `Failed to remove tag, ${e}`)
|
|
160
|
+
}
|
|
161
|
+
}))
|
|
162
|
+
return data
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export default TagsModule
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "adapt-authoring-tags",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Module for managing tags",
|
|
5
|
+
"homepage": "https://github.com/adapt-security/adapt-authoring-tags",
|
|
6
|
+
"license": "GPL-3.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"repository": "github:adapt-security/adapt-authoring-tags",
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"adapt-authoring-api": "github:adapt-security/adapt-authoring-api",
|
|
12
|
+
"adapt-authoring-core": "github:adapt-security/adapt-authoring-core",
|
|
13
|
+
"adapt-authoring-mongodb": "github:adapt-security/adapt-authoring-mongodb"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"eslint": "^9.12.0",
|
|
17
|
+
"standard": "^17.1.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$anchor": "tag",
|
|
4
|
+
"description": "Tag metadata applied to other objects",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"title": {
|
|
8
|
+
"description": "The tag title",
|
|
9
|
+
"type": "string"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"required": ["title"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$anchor": "tags",
|
|
4
|
+
"description": "Extra properties to define tags",
|
|
5
|
+
"$merge": {
|
|
6
|
+
"with": {
|
|
7
|
+
"properties": {
|
|
8
|
+
"tags": {
|
|
9
|
+
"title": "Tags",
|
|
10
|
+
"description": "Add tags by entering one or more words, separated with a comma (,)",
|
|
11
|
+
"type": "array",
|
|
12
|
+
"default": [],
|
|
13
|
+
"uniqueItems": true,
|
|
14
|
+
"items": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"isObjectId": true
|
|
17
|
+
},
|
|
18
|
+
"_backboneForms": "Tags"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|