-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store import logs and add API to access them
- Loading branch information
Showing
14 changed files
with
297 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: '3' | ||
services: | ||
db: | ||
image: couchdb:2.3 | ||
environment: | ||
COUCHDB_USER: admin | ||
COUCHDB_PASSWORD: admin | ||
ports: | ||
- 127.0.0.1:5984:5984 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const globalRightTypes = [ | |
'readGroup', | ||
'writeGroup', | ||
'createGroup', | ||
'readImport', | ||
'owner', | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const CouchError = require('../util/CouchError'); | ||
const debug = require('../util/debug')('main:imports'); | ||
|
||
const validateMethods = require('./validate'); | ||
|
||
const methods = { | ||
async logImport(toLog) { | ||
toLog.$type = 'import'; | ||
toLog.$creationDate = Date.now(); | ||
await this._db.insertDocument(toLog); | ||
}, | ||
|
||
async getImports(user, query) { | ||
await this.open(); | ||
debug('get imports (%s)', user); | ||
|
||
const hasRight = await validateMethods.checkRightAnyGroup( | ||
this, | ||
user, | ||
'readImport', | ||
); | ||
if (!hasRight) { | ||
throw new CouchError( | ||
'user is missing read right on imports', | ||
'unauthorized', | ||
); | ||
} | ||
|
||
const imports = await this._db.queryView( | ||
'importsByDate', | ||
{ | ||
descending: true, | ||
include_docs: true, | ||
limit: query.limit || 10, | ||
skip: query.skip || 0, | ||
}, | ||
{ onlyDoc: true }, | ||
); | ||
|
||
return imports; | ||
}, | ||
|
||
async getImport(user, uuid) { | ||
await this.open(); | ||
debug('get import (%s, %s)', user, uuid); | ||
|
||
const hasRight = await validateMethods.checkRightAnyGroup( | ||
this, | ||
user, | ||
'readImport', | ||
); | ||
if (!hasRight) { | ||
throw new CouchError( | ||
'user is missing read right on imports', | ||
'unauthorized', | ||
); | ||
} | ||
|
||
const doc = await this._db.getDocument(uuid); | ||
if (!doc) { | ||
throw new CouchError('document not found', 'not found'); | ||
} | ||
if (doc.$type !== 'import') { | ||
throw new CouchError( | ||
`wrong document type: ${doc.$type}. Expected: import`, | ||
); | ||
} | ||
|
||
return doc; | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
methods, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,6 @@ module.exports = async function saveResult(importBase, result) { | |
}, | ||
); | ||
} | ||
|
||
return document.id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = async function errorImport() { | ||
throw new Error('this import is wrong'); | ||
}; |
Oops, something went wrong.