Skip to content

Commit

Permalink
Merge pull request #6 from the-t-in-rtf/GPII-3921
Browse files Browse the repository at this point in the history
GPII-3921: Update gpii-express-user to use modern dependencies, especially gpii-json-schema.
  • Loading branch information
the-t-in-rtf authored Jul 10, 2020
2 parents d5b0331 + bc104fa commit 364d0cc
Show file tree
Hide file tree
Showing 68 changed files with 697 additions and 842 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "eslint-config-fluid"
"extends": "eslint-config-fluid"
}
8 changes: 0 additions & 8 deletions .istanbul.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"reporter": ["none"],
"report-dir": "reports",
"temp-dir": "coverage",
"clean": false,
"exclude": ["**/tests/**/*.js"]
}
8 changes: 7 additions & 1 deletion .vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ setup_job:
stage: setup
script:
- choco install nodejs-lts -y
- choco upgrade googlechrome -y
- choco install chromedriver -y
- choco install wget -y
- "do.ps1 -c 'cd /users/vagrant/downloads && wget http://dl.bintray.com/apache/couchdb/win/2.3.0/couchdb-2.3.0.msi'"
- "do.ps1 -c 'cd /users/vagrant/downloads && msiexec.exe /i couchdb-2.3.0.msi /passive'"
- "do.ps1 -c 'v: && npm install && node node_modules/gpii-couchdb-test-harness/provisioning/configureCouch.js'"
- "do.ps1 -c 'npm install -g grunt'"

test_job:
stage: test # name of the stage
script: # One line per command to execute
- "do.ps1 -c 'v: && npm install && npm test'"
- "do.ps1 -c 'set GPII_TEST_COUCH_USE_EXTERNAL=true && set HEADLESS=true && v: && npm install && npm test'"
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (grunt) {
sources: {
md: [ "./*.md","./docs/*.md"],
js: ["./src/**/*.js", "./tests/**/*.js", "./*.js"],
json: ["./*.json", "tests/**/*.json", "src/**/*.json"],
json: ["./*.json", "tests/**/*.json", "src/**/*.json", "./.nycrc"],
json5: [],
other: ["./.*"]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/apiComponent.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ this component supports the following unique options:
| `app.url` | `{String}` | The public facing URL for this application. |
| `couch.port` | `{String}` | The port on which our CouchDB instance runs. |
| `couch.userDbName` | `{String}` | The CouchDB database name containing our user records. Defaults to `users`. |
| `couch.userDbUrl` | `{String}` | The URL of our CouchDB instance. By default this is expanded from `userDbName` above using the pattern `http://admin:admin@localhost:%port/%userDbName` (see above). |
| `couch.userDbUrl` | `{String}` | The URL of our CouchDB instance. By default this is expanded from `userDbName` above using the pattern `http://localhost:%port/%userDbName` (see above). |
| `schemaDirs` | `{Array}` | An array of schema directories that contain our [JSON Schemas](http://json-schema.org/). Supports package-relative paths like '%gpii-express-user/src/templates'. |
| `templateDirs` | `{Array}` | An array of template directories that contain our Handlebars templates. Supports package-relative paths like "%gpii-express-user/src/templates". |

Expand Down
48 changes: 2 additions & 46 deletions docs/apidocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Returns details about the current user if they are logged in, as in:

```json
{
"ok": true,
"user": {
"username": "sample",
"email": "[email protected]"
Expand All @@ -28,13 +27,11 @@ Returns an error message if the user is not currently logged in, as in:

```json
{
"ok": false,
"isError": true,
"message": "You are not currently logged in."
}
```

[Response schema](../schemas/user-message.json)

### `POST /api/user/login`

Log a user in. Requires both a `username` and `password`, as in:
Expand All @@ -46,19 +43,14 @@ Log a user in. Requires both a `username` and `password`, as in:
}
```

[Request schema](../schemas/user-login.json)

Returns a confirmation message indicating whether the login was successful, as in:

```json
{
"ok": true,
"message": "You are now logged in."
}
```

[Response schema](../schemas/user-message.json)

Note that only users with verified email addresses are allowed to log in. For details, see `GET /api/user/verify/:code`
below.

Expand All @@ -68,13 +60,10 @@ Immediately logs the current user out and returns a confirmation message, as in:

```json
{
"ok": true,
"message": "You are now logged out."
}
```

[Response schema](../schemas/user-message.json)

### `POST /api/user`

Create a new user. Anyone can create a user, but the account cannot be used until the email address is verified (see
Expand All @@ -92,19 +81,15 @@ Requires a `username`, valid `password`, and a `confirm` field with the same pas
}
```

[Request schema](../schemas/user-signup.json)

Returns a confirmation message indicating whether the response was successful, as in:

```json
{
"ok": false,
"isError": true,
"message": "A user with this email address already exists."
}
```

[Response schema](../schemas/user-message.json)

### `GET /api/user/verify/:code`

When a new account is created, an email is sent to the address associated with the account. The email contains a link
Expand All @@ -115,13 +100,10 @@ account. A successful response should look something like:

```json
{
"ok": true,
"message": "Your email address has been verified and you can now use your account to log in."
}
```

[Response schema](../schemas/user-message.json)

### `POST /api/user/verify/resend/:email`

If a user loses their initial verification email, they can ask for it to be sent again by supplying the `email` address
Expand All @@ -135,20 +117,14 @@ they used when signing up, as in:

Returns a confirmation message indicating whether the response was successful.

[Response schema](../schemas/user-message.json)

### `GET /api/user/forgot/:email`

Users can request a link that can be used to reset their password. This is a three step process. The first step
(handled by this endpoint) sends a message to the supplied `email` address. For the second step, see `GET
/api/user/reset/:code` below.

[Request schema](../schemas/user-forgot.json)

Returns a confirmation message indicating whether the response was successful.

[Response schema](../schemas/user-message.json)

### `GET /api/user/reset/:code`

If a user has requested that their password be reset using the `GET /api/user/forgot/:email` API endpoint (see above),
Expand All @@ -157,8 +133,6 @@ they will receive an email message that contains a link to this endpoint.
By visiting this link, they are presented with a form that will allow them update their password using the `POST
/api/user/reset/:code` endpoint (see below)

[Response schema](../schemas/user-message.json)

### `POST /api/user/reset/:code`

Allows a user to reset their password using a `code` received via email (see `GET /api/user/forgot/:email`). The user
Expand All @@ -171,12 +145,8 @@ is required to enter a valid `password` and to enter the same password in a `con
}
```

[Request schema](../schemas/user-reset.json)

Returns a confirmation of whether the response was successful.

[Response schema](../schemas/user-message.json)

## /api/group

The following endpoints are used to manage groups. All parts of the group API require the user to be an administrator.
Expand All @@ -185,8 +155,6 @@ The following endpoints are used to manage groups. All parts of the group API r

Displays the group metadata as well as the `username` of all members of `:group`.

[Response schema](../schemas/group-message.json)

### `POST /api/group/:group`

Create a new group named `:group`. A group is required to have a valid (URL-safe) `name`, and may optionally include a
Expand All @@ -199,18 +167,12 @@ list of `members`, each of which is expected to be valid `username`, as in:
}
```

[Request schema](../schemas/group-core.json)

Returns a confirmation of whether the response was successful.

[Response schema](../schemas/group-message.json)

### `DELETE /api/group/:group`

Delete the group named `:group`. Returns a confirmation of whether the response was successful.

[Response schema](../schemas/group-message.json)

## /api/memberships

The following endpoints are used to manage the membership of users in one or more groups. An individual user can only
Expand All @@ -221,17 +183,11 @@ view their own memberships, using `GET /api/memberships/:username` (see below).
Displays a list of group memberships for the given `:username`. If `:username` is omitted, the memberships for the
current user are displayed. For a list of users in a single group, see `GET /api/group/:group` above.

[Response schema](../schemas/memberships-message.json)

### `POST /api/memberships/:username/:group`

Add `:username` to `:group`. Does not expect and will ignore any JSON data you send. Returns a confirmation of whether
the response was successful.

[Response schema](../schemas/message-core.json)

### `DELETE /api/memberships/:username/:group`

Remove `:username` from `:group`. Returns a confirmation of whether the response was successful.

[Response schema](../schemas/message-core.json)
2 changes: 1 addition & 1 deletion docs/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This component requires the same CouchDB options as other components in this mod
| ------------------ | ---------- | ----------- |
| `couch.port` | `{String}` | The port on which our CouchDB instance runs. |
| `couch.userDbName` | `{String}` | The CouchDB database name containing our user records. Defaults to `users`. |
| `couch.userDbUrl` | `{String}` | The URL of our CouchDB instance. By default this is expanded from `userDbName` above using the pattern `http://admin:admin@localhost:%port/%userDbName` (see above). |
| `couch.userDbUrl` | `{String}` | The URL of our CouchDB instance. By default this is expanded from `userDbName` above using the pattern `http://localhost:%port/%userDbName` (see above). |

### Component Invokers

Expand Down
53 changes: 29 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"name": "gpii-express-user",
"version": "1.0.2",
"description": "A series of Fluid components to provide simple user management.",
"main": "src/js/index.js",
"main": "index.js",
"scripts": {
"test": "node node_modules/istanbul/lib/cli.js cover tests/all-tests.js"
"pretest": "node node_modules/rimraf/bin.js coverage/* reports/* instrumented/*",
"test": "npm run test:webdriver && npm run test:node",
"test:webdriver": "node tests/js/browser/index.js",
"test:node": "node node_modules/nyc/bin/nyc.js node tests/js/server/index.js",
"posttest": "node node_modules/nyc/bin/nyc.js report --reporter html --reporter text-summary"
},
"repository": {
"type": "git",
Expand All @@ -17,31 +21,32 @@
},
"homepage": "https://github.com/GPII/gpii-express-user",
"dependencies": {
"foundation-sites": "6.3.1",
"gpii-binder": "1.0.3",
"gpii-express": "1.0.14",
"gpii-handlebars": "1.1.0",
"gpii-json-schema": "1.0.5",
"infusion": "3.0.0-dev.20180326T173646Z.8c6a109b1",
"kettle": "1.7.3",
"markdown-it": "8.4.1",
"nodemailer": "4.6.7",
"foundation-sites": "6.6.3",
"gpii-binder": "1.1.0",
"gpii-express": "1.0.15",
"gpii-handlebars": "2.1.2",
"gpii-json-schema": "2.1.3",
"infusion": "3.0.0-dev.20200528T154535Z.9cd9261.FLUID-6145",
"kettle": "1.12.0",
"markdown-it": "11.0.0",
"nodemailer": "6.4.8",
"nodemailer-smtp-transport": "2.7.4",
"request": "2.87.0"
"request": "2.88.2"
},
"devDependencies": {
"cookie": "0.3.1",
"eslint": "5.1.0",
"eslint-config-fluid": "1.3.0",
"gpii-grunt-lint-all": "1.0.1-dev.20180706T153657Z.4cbbd61",
"gpii-mail-test": "1.0.3",
"gpii-pouchdb": "1.0.12",
"gpii-webdriver": "1.0.2",
"grunt": "1.0.3",
"handlebars": "4.0.11",
"istanbul": "0.4.5",
"mailparser": "0.6.2",
"cookie": "0.4.1",
"eslint-config-fluid": "1.4.0",
"eslint": "7.1.0",
"gpii-couchdb-test-harness": "1.0.1",
"gpii-grunt-lint-all": "1.0.7",
"gpii-mail-test": "1.0.6",
"gpii-webdriver": "1.1.0",
"grunt": "1.1.0",
"handlebars": "4.7.6",
"mailparser": "2.7.7",
"node-jqunit": "1.1.8",
"pagedown": "1.1.0"
"nyc": "15.0.1",
"pagedown": "1.1.0",
"rimraf": "3.0.2"
}
}
4 changes: 2 additions & 2 deletions src/js/client/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type: "GET",
url: "/api/user/logout"
},
templates: {
templateKeys: {
initial: "controls-viewport"
},
rules: {
Expand Down Expand Up @@ -65,7 +65,7 @@
},
renderInitialMarkup: {
func: "{that}.renderMarkup",
args: ["initial", "{that}.options.templates.initial", "{that}.model", "html"]
args: ["initial", "{that}.options.templateKeys.initial", "{that}.model", "html"]
}
},
listeners: {
Expand Down
20 changes: 20 additions & 0 deletions src/js/client/errorAwareForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function (fluid) {
"use strict";
fluid.defaults("gpii.express.user.frontend.errorAwareForm", {
gradeNames: ["gpii.schema.client.errorAwareForm"],
resources: {
modelSchema: {
promiseFunc: "{schemaHolder}.generateSchema"
}
},
modelSchema: "{that}.model.modelSchema",
model: {
modelSchema: "{that}.resources.modelSchema.parsed"
},
components: {
schemaHolder: {
type: "gpii.express.user.schemaHolder"
}
}
});
})(fluid);
15 changes: 9 additions & 6 deletions src/js/client/forgot.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Provide a front-end to allow users to request that their password be reset...
/* global fluid, jQuery */
(function () {
"use strict";
fluid.defaults("gpii.express.user.frontend.forgot", {
gradeNames: ["gpii.schemas.client.errorAwareForm"],
schemaKey: "user-forgot.json",
gradeNames: ["gpii.express.user.frontend.errorAwareForm"],
ajaxOptions: {
type: "POST",
url: "/api/user/forgot"
type: "POST",
url: "/api/user/forgot"
},
model: {
email: ""
Expand All @@ -22,9 +20,14 @@
bindings: {
"email": "email"
},
templates: {
templateKeys: {
"initial": "forgot-viewport",
"success": "success"
},
components: {
schemaHolder: {
type: "gpii.express.user.schemaHolder.forgot"
}
}
});

Expand Down
Loading

0 comments on commit 364d0cc

Please sign in to comment.