Skip to content

Commit

Permalink
Merge pull request #73 from datasci4health/development
Browse files Browse the repository at this point in the history
Development Deploy 07-08-2020
  • Loading branch information
marcosfmmota authored Aug 7, 2020
2 parents 272254d + 2a0fee5 commit ee2d469
Show file tree
Hide file tree
Showing 69 changed files with 4,527 additions and 304 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ typings/

.idea/
.chglog/

src/adonisjs/public/artifacts/cases/

# vscode configuration file
.vscode/
94 changes: 94 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<a name="unreleased"></a>
## [Unreleased]

### Features
- 🎸 Auth mechanism with `refresh token`: From now on, `POST auth/login/` responds with a pair of `<<token, refresh token>>`. `refresh_token` must be used to re-signin the user
whose `token` was revoked by `harena-manager` server.

✅ Closes issue #70

- 🎸 Enable `logout` through endpoint `POST auth/logout`
- 🎸 Newly created REST endpoint `POST /admin/institution` for create a new institution
- 🎸 Newly created REST endpoints: `GET auth/quest/cases` and `GET play/quest/cases`

✅ Closes: #71

- 🎸 Migrate database - Related issue: [#62](https://github.com/datasci4health/harena-manager/issues/23)
- 🎸 Share cases: Allows the author associate more contributors to her case
- 🎸 Auth: Implement adonis ACL to control roles and permissions - Closes issue: #40
- 🎸 Provide quest services
✅ Closes issue #37

### Fix
- Error on delete case. Related issue: [#23](https://github.com/datasci4health/harena-manager/issues/23)
- Enable upload of .jpeg files

### Chore
- 🤖 dependency update: Apply suggestions made by dependabot alerts
- 🤖 docker: Provide a develop environment to be used by collaborators team.
Thecontainer orchastrate the whole environment (harenamanager, database,
and database-ui).

### Docs
- ✏️ Add auth sequence diagram
- ✏️ Add a schema versioning mechanism. It keeps the track of 3 such files: schema.dia,
schema.pdf, schema.png. They are representations of the schema defined
on database/migrations. Schemas are located at https://github.com/datasci4health/harena-manager/tree/development/src/adonisjs/database/schema_design)
- ✏️ Added a CHANGELOG in the project.


<!-- ### Performance Improvements
- ⚡️ improvement on auth mechanism: Enable `logout` through the endpoint `POST auth/logout`
-->
### Refactor
<!-- - 💡 improvements on REST endpoints: Refactoring code related to REST endpoints -->
- 💡 Implements hooks through `file.method`

### BREAKING CHANGE

`POST /case/list` was replaced by two new endpoints: `GET /cases` and
`GET /user/:id/cases`

<a name="v1.0.8"></a>
## [v1.0.8] - 2020-03-22

### Error
- There was an error connecting to http://localhost:10020/api/v1/quest.

### Feat
- 🎸 Provide quest services

<a name="v1.0.7"></a>
## [v1.0.7] - 2019-08-05
### Build
- **docker:** A docker image of develop environment avaivable

### Fix
- **artifact:** Enable upload of .jpeg files
- **artifact:** Fix error at artifact upload

<a name="v1.0.5"></a>
## [v1.0.5] - 2019-07-07
### Bug
- Error on delete case - [#23](https://github.com/datasci4health/harena-manager/issues/23)

### Docs
- ✏️ Add a CHANGELOG.

<a name="v0.0.1"></a>
## v0.0.1 - 2019-04-15

[Unreleased]: https://github.com/datasci4health/harena-manager/compare/v1.0.11...HEAD
[v1.0.11]: https://github.com/datasci4health/harena-manager/compare/v1.0.10...v1.0.11
[v1.0.10]: https://github.com/datasci4health/harena-manager/compare/v1.0.9...v1.0.10
[v1.0.9]: https://github.com/datasci4health/harena-manager/compare/v1.0.8...v1.0.9
[v1.0.8]: https://github.com/datasci4health/harena-manager/compare/v1.0.7...v1.0.8
[v1.0.7]: https://github.com/datasci4health/harena-manager/compare/v1.0.6...v1.0.7
[v1.0.6]: https://github.com/datasci4health/harena-manager/compare/v1.0.5...v1.0.6
[v1.0.5]: https://github.com/datasci4health/harena-manager/compare/v1.0.4...v1.0.5
[v1.0.4]: https://github.com/datasci4health/harena-manager/compare/v1.0.3...v1.0.4
[v1.0.3]: https://github.com/datasci4health/harena-manager/compare/v1.0.1...v1.0.3
[v1.0.1]: https://github.com/datasci4health/harena-manager/compare/v1.0.2...v1.0.1
[v1.0.2]: https://github.com/datasci4health/harena-manager/compare/v1.0.0...v1.0.2
[v1.0.0]: https://github.com/datasci4health/harena-manager/compare/v0.1.0...v1.0.0
[v0.1.0]: https://github.com/datasci4health/harena-manager/compare/v0.0.1...v0.1.0
36 changes: 11 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,16 @@

# Harena Manager

Harena's Database Access API.
Harena's database management module
> It provides an api for data access
## Table of contents
## Available end points

<!-- MarkdownTOC autolink=true -->

- [Change log](#change-log)
- [Getting Started](#getting-started)
- [Access harena-manager service](#running-locally---linux)
- [Running as Docker containers - Linux](#running-as-docker-containers---linux)
- [Contributing](#contributing)
- [Branch organization](#branch-organization)

<!-- /MarkdownTOC -->

## Change log

The change log can be found in the CHANGELOG.md file.
Check https://documenter.getpostman.com/view/7243662/T1Ds8ag7?version=latest to discover available endpoints provided by `harena manager api`.

## Getting Started

### Access `harena-manager` service

`<URL_HARENA_MANAGER>`

### Running locally within docker containers

We provide a docker container to run `harena-manager` code. Containers usage guarantees the minimal configuration required to run the code. Read [docker](https://docs.docker.com/install/) e [docker-compose](https://docs.docker.com/compose/install/) documentations to install docker and learn further about containers.
We provide a `docker container` to locally run `harena-manager` code. Containers guarantee the required minimal configuration to run the code. Read [docker](https://docs.docker.com/install/) e [docker-compose](https://docs.docker.com/compose/install/) documentations to install docker and learn further about containers.

#### Instructions (for Linux users)

Expand All @@ -49,13 +31,13 @@ docker build . -t manager
cd ..
```

Then, up the docker container:
Start up the docker container:

```bash
docker-compose -f docker-compose-dev.yml up
```

After starting the container, access http://localhost:10020/ to check if the system is up.
Once the start up process is done, access http://localhost:10020/ to check if the system is working.

If you want to get the command line of the container, then run the command:

Expand Down Expand Up @@ -109,3 +91,7 @@ docker exec -it harena-manager_harena-manager_1 bash
* new bugs registered on the issue list https://github.com/datasci4health/harena-manager/issues.
* `tags`:
* Are used for creating Dockerhub image versions at https://cloud.docker.com/u/datasci4health/repository/docker/datasci4health/harena-manager .

## Change log

Release updates can be found at [CHANGELOG.md](https://github.com/datasci4health/harena-manager/blob/development/CHANGELOG.md) file.
80 changes: 80 additions & 0 deletions src/adonisjs/app/Controllers/Http/AuthController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict'

const User = use('App/Models/v1/User');
const Token = use('App/Models/v1/Token');

class AuthController {

async login({ request, auth, response }) {
console.log(request.all())
let { email, password, refresh_token } = request.all();
let user = ""
let token = ""

try{
await auth.check()
return response.json('user is signed already')
} catch(e) {
console.log(e)
// token expired
if (e.code == 'E_JWT_TOKEN_EXPIRED'){
token = await auth.generateForRefreshToken(refresh_token)

Object.entries(token).forEach(entry => {
if (entry[0] == 'refreshToken'){
refresh_token = entry[1]
}
});
}

// unloged user
if (e.code == 'E_INVALID_JWT_TOKEN'){
console.log(7)
try{
token = await auth.withRefreshToken().attempt(email, password)
} catch(e){
console.log('erro aqui')
console.log(e)
}
}

// generic error
if (token == "")
return response.status(e.status).json(e.message)

user = await User.findBy('email', email)
Object.assign(user, token)

return response.json(user)
}
}

async login2({ request, auth, response }) {
try{
let refresh_token = request.input('access_code');

let token = await auth.generateForRefreshToken(refresh_token)
return response.json(token)
}catch(e){
console.log(e)
return response.status(500).json(e.message)
}

}

async logout({ auth, response }) {
try{

const refreshToken = auth.getAuthHeader()
await auth.revokeTokens(refreshToken)

return response.json('successfull logout')
}catch(e){
console.log(e)
return response.status(500).json(e.message)
}

}
}

module.exports = AuthController
37 changes: 35 additions & 2 deletions src/adonisjs/app/Controllers/Http/v1/AdminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */

const Database = use('Database')

const Role = use('Adonis/Acl/Role');
const Permission = use('Adonis/Acl/Permission');
const User = use('App/Models/v1/User');
Expand Down Expand Up @@ -93,7 +95,6 @@ class AdminController {

async list_roles({ response }) {
try{
console.log('chegou')
let roles = await Role.all()
return response.json(roles)
} catch(e){
Expand Down Expand Up @@ -121,7 +122,7 @@ class AdminController {
}
}

async list_permissions_by_user({ params, response }) {
async list_permissions_by_role({ params, response }) {
try{
let role = await Role.find(params.id)

Expand All @@ -131,6 +132,38 @@ class AdminController {
return response.status(500).json({ message: e.message })
}
}

async list_permissions_by_user({ params, response }) {
try{

let user = await User.find(params.id)

// let role = await Role.find(params.id)

return response.json(await user.getPermissions())
} catch(e){
console.log(e)
return response.status(500).json({ message: e.message })
}
}

async revoke_tokens({ auth, params, response }) {
try{
// await user.tokens().update({ is_revoked: true })
// console.log('antes')
// console.log(await auth.listTokens())
// // const affectedRows = await Database
// // .table('tokens').update('is_revoked', true)
// // console.log(affectedRows)
// console.log('depois')
// console.log(await auth.listTokens())
await auth.revokeTokens()
return response.json('tokens revoked')
} catch(e){
console.log(e)
return response.status(500).json({ message: e.message })
}
}
}

module.exports = AdminController
40 changes: 21 additions & 19 deletions src/adonisjs/app/Controllers/Http/v1/ArtifactController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArtifactController {
extnames: ['png', 'jpg', 'jpeg', 'gif','mp4','avi', '.wmv']
}

this.relativePath = '/artifacts/'
this.relativePath = '/resources/artifacts/'


}
Expand All @@ -25,38 +25,38 @@ class ArtifactController {
try{

const file = request.file('file', this.validationOptions)
const caseID = request.input('case_uuid', null)
const case_id = request.input('case_id', null)

var linkedCase = await Case.find(caseID)
var c = await Case.find(case_id)

if (caseID != null && linkedCase == null){
console.log(c)
if (case_id != null && c == null){
return response.json({ message: "Case id not found" })
}

let fsPath = Helpers.publicPath(this.relativePath)
let caseRelativePath = this.relativePath
if (caseID != null){
fsPath += 'cases/' + caseID + '/'
caseRelativePath += 'cases/' + caseID + '/'
let fs_path = Helpers.publicPath(this.relativePath)
let case_relative_path = this.relativePath
if (case_id != null){
fs_path += 'cases/' + case_id + '/'
case_relative_path += 'cases/' + case_id + '/'
}

const artifactID = await uuid4()
const artifactFileName = artifactID + "." + file.extname
const artifact_id = await uuid4()
const artifact_file_name = artifact_id + "." + file.extname

await file.move(fsPath, {name: artifactFileName, overwrite: false})
await file.move(fs_path, {name: artifact_file_name, overwrite: false})

const artifact = new Artifact()
artifact.id = artifactID
artifact.fs_path = fsPath + artifactFileName
artifact.relative_path = caseRelativePath + artifactFileName
artifact.case_id = linkedCase != null ? linkedCase.uuid : linkedCase;
await auth.user.artifacts().save(artifact)
artifact.id = artifact_id
artifact.fs_path = fs_path + artifact_file_name
artifact.relative_path = case_relative_path + artifact_file_name
artifact.case_id = c != null ? c.id : c;

const base_url = Env.getOrFail('APP_URL')

let bodyMessage = { message: "Artifact successfully stored",
filename: artifactFileName,
case: linkedCase,
filename: artifact_file_name,
case: c,
size_in_bytes: file.size,
type: file.type,
subtype: file.subtype,
Expand All @@ -66,6 +66,8 @@ class ArtifactController {
url: base_url+artifact.relative_path
}

await auth.user.artifacts().save(artifact)

return response.status(200).json(bodyMessage)
} catch(e){
console.log(e)
Expand Down
Loading

0 comments on commit ee2d469

Please sign in to comment.