Skip to content

Commit

Permalink
Merge pull request #52 from bioinformatics-ua/bug/user-add-delete
Browse files Browse the repository at this point in the history
Fix operations to add and delete users
  • Loading branch information
Enet4 authored Sep 16, 2022
2 parents 90aaf23 + 2d7d13c commit b9ad624
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 102 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"eol-last": 1,
"no-undef": 2,
"valid-jsdoc": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-unused-vars": [1, {
"args": "none",
"vars": "local",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [ master, release/5.x ]
pull_request:
branches: [ master ]
branches: [ master, release/5.x ]

jobs:
build:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"vinyl-source-stream": "^2.0.0"
},
"scripts": {
"check": "eslint --fix src/ test/*.js test/mock/*.js",
"check": "eslint --fix src/ test/*.ts test/mock/*.ts",
"strictCheck": "eslint src/ test/*.ts test/mock/*.ts",
"build": "npm run check && npm run prepare && gulp bundle",
"prepare": "tsc",
"clean": "rimraf dist lib coverage .nyc_output docs",
Expand Down
12 changes: 10 additions & 2 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ export class UserService {
* @param admin whether the account is an administrator
*/
add(username: string, password: password, admin: boolean, callback?: (error: Error | null, success?: boolean) => void): Promise<boolean> {
return andCall(this.socket.put(Endpoints.USER).query({username, password, admin})
return andCall(this.socket.post(Endpoints.USER).query({username, password, admin})
.catch((err) => {
if (err.status === 405) {
// method not allowed means that we're using Dicoogle 2,
// so we try again with the PUT method
return this.socket.put(Endpoints.USER).query({username, password, admin});
}
throw err;
})
.then((res) => res.body.success), callback);
}

Expand All @@ -59,7 +67,7 @@ export class UserService {
* @param username the identifier of the user to remove
*/
remove(username: string, callback?: (error: Error | null, removed?: boolean) => void): Promise<boolean> {
return andCall(this.socket.request('DELETE', Endpoints.USER).query({username})
return andCall(this.socket.request('DELETE', [Endpoints.USER, username])
.then((res) => res.body.success), callback);
}
}
14 changes: 12 additions & 2 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"root": true,
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"env": {
"commonjs": true,
"node": true,
"es6": true
},
Expand All @@ -16,13 +24,15 @@
"rules": {
"no-alert": 2,
"no-console": 1,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"quotes": 0,
"curly": 0,
"global-strict": 0,
"new-cap": 0,
"camelcase": 0,
"comma-dangle": 0,
"no-unused-vars": 1,
"no-unused-vars": 0,
"comma-spacing": 1,
"space-infix-ops": 1,
"no-mixed-spaces-and-tabs": 1,
Expand Down
8 changes: 4 additions & 4 deletions test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
/* eslint-env mocha */
import {assert} from 'chai';
import createMockedDicoogle from './mock/service-auth-mock';
var UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
const UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;

describe('Dicoogle Authentication', function() {
var Dicoogle;
let Dicoogle;
function initBaseURL() {
Dicoogle = createMockedDicoogle();
assert.strictEqual(Dicoogle.getBase(), 'http://127.0.0.1:8484');
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Dicoogle Authentication', function() {
});

describe('Loading a previous session', function() {
var TOKEN = '00000000-0000-0000-0000-000000000001';
const TOKEN = '00000000-0000-0000-0000-000000000001';
it('#setToken(string) should modify the session token', function() {
Dicoogle.setToken(TOKEN);
assert.strictEqual(Dicoogle.getToken(), TOKEN);
Expand All @@ -136,7 +136,7 @@ describe('Dicoogle Authentication', function() {
});

it("clear and restore previous session ; should give user name, admin and roles", function(done) {
var token = Dicoogle.getToken();
const token = Dicoogle.getToken();
Dicoogle.reset();

Dicoogle.restoreSession(token, function(error, data) {
Expand Down
Loading

0 comments on commit b9ad624

Please sign in to comment.