maj prod
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const express = require( 'express' );
|
||||
const fs=require('fs-extra');
|
||||
const conf = require(`${process.env.dirtown}/conf.json`);
|
||||
|
||||
// Classes
|
||||
@@ -9,32 +10,26 @@ const isAuthenticated = require( '../middlewares/isAuthenticated' );
|
||||
const router = express.Router();
|
||||
|
||||
/*
|
||||
Manage the social world
|
||||
|
||||
@Todo
|
||||
|
||||
Manage a new nation
|
||||
Manage nation
|
||||
A major create a nation with at least a town => nation:{name, towns:[]} contracts/nationname.js + contracts/townsname.js
|
||||
Manage a new towns in a nation => update nation:[nationname:towns:[]} contracts/townname.js
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
router.post( '/push', checkHeaders, ( req, res ) => {
|
||||
// Get information from other apxtrib instance in req.body
|
||||
// check req.body.hashnext => means this is a candidate to validate next block
|
||||
//
|
||||
// return it's own information back with the last call to Nationchains.synchronize()
|
||||
res.send( { status: 200, payload: { moreinfo: fs.readFileSync( `${conf.tribes}/${conf.mayorId}/nationchains/nodes/${conf.rootURL}`, 'utf-8' ) } } )
|
||||
|
||||
|
||||
/**
|
||||
* @api {put} /nations/viewtown/:town - nationlist from a town major
|
||||
* @apigroup Nation
|
||||
* @apiName nationlist
|
||||
* @apiDescription get list of nation from a town to help this instance to update network topology
|
||||
* @apiParam {string} town fromwhich the data come from
|
||||
* @apiSuccess {object} refreshnetworktopoly
|
||||
* * HTTP/1.1 200 OK
|
||||
* {status:200,ref:"Nations",msg:"updated",data:{}};
|
||||
*
|
||||
*/
|
||||
router.put( '/', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
const uptown = Nations.updatetown()
|
||||
res.status(uptown.status).send(uptown)
|
||||
} )
|
||||
|
||||
router.get('/synchro',checkHeaders, isAuthenticated,(req,res)=>{
|
||||
// run a sync from a list of electedtown to update nationchains folder
|
||||
console.log('TODO')
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
|
@@ -1,9 +1,6 @@
|
||||
const express = require("express");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
// Classes
|
||||
const Pagans = require("../models/Notifications.js");
|
||||
const Notifications = require("../models/Notifications.js");
|
||||
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
@@ -12,48 +9,22 @@ const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* Get form data and send notification to user by email, sms, alert
|
||||
* @api{post}/messageanonymous
|
||||
* @apiName Notification
|
||||
* @apiDescription Send information as anonymous to tribe's druid
|
||||
* @apiGroup apxtrib
|
||||
* @api {get} /notifications/:alias/:tribeId
|
||||
* @apiName notiflist
|
||||
* @apiDescription Get list of notifications for an alias and a tribe
|
||||
* @apiGroup Notification
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
* @apiParam {string} objectname Mandatory
|
||||
* @apiParam {String} indexname Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname/idx/indexname indexname contains the ObjectName .*_ (before the first _)
|
||||
*
|
||||
*
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"Odmdb","msg":"pathnamedoesnotexist","data":{indexpath}}
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiParam {string} alias
|
||||
* @apiParam {string} tribeId
|
||||
* @apiSuccess {object} notif content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
|
||||
* {status:200,ref:"Notification",msg:"Messagelist",data:{notif:[{tribeId,msg:{from(email or uuid or alias):[{dt,msg}]}}]}
|
||||
*
|
||||
*
|
||||
**/
|
||||
router.get("/alias/:alias", (req, res) => {
|
||||
const getalias = Pagans.getalias(req.params.alias);
|
||||
router.get("/:alias/:tribeId", (req, res) => {
|
||||
const getnot = Notification.get(req.params.alias,req.params.tribeId);
|
||||
res.status(getalias.status).send(getalias);
|
||||
});
|
||||
/**
|
||||
* Remove serveur token
|
||||
* @api {get} /pagans/logout
|
||||
* @apiName Remove token
|
||||
* @apiGroup Pagans
|
||||
*
|
||||
*/
|
||||
router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(req.session.header);
|
||||
const logout = Pagans.logout(
|
||||
req.session.header.xalias,
|
||||
req.session.header.xtribe,
|
||||
req.session.header.xdays,
|
||||
req.session.header.xhash
|
||||
);
|
||||
res.status(logout.status).json(logout);
|
||||
});
|
||||
|
||||
module.exports=router;
|
@@ -9,13 +9,52 @@ const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
/**
|
||||
* @api{get}/odmdb/idx/:objectname/:indexname - index Get
|
||||
* @api {get} /odmdb/objects - objects Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get objects available for header.xtribe
|
||||
*
|
||||
* @apiSuccess {object} contain data.indexname
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"objectslist", "data":{indexname,content:{index file}}
|
||||
*
|
||||
*
|
||||
*/
|
||||
router.get("/objects", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const data = {
|
||||
tribe: req.session.headers.xtribe,
|
||||
apx: { conf: {}, objectnames: [] },
|
||||
tribe: { conf: {}, objectnames: [] },
|
||||
};
|
||||
glob.sync(`${conf.dirapi}/adminapi/schema/*.json`).forEach((f) => {
|
||||
const objectname = path.basename(f, ".json");
|
||||
if (objectname == "conf") {
|
||||
data.apx.conf = fs.readJSONSync(f);
|
||||
} else {
|
||||
data.apx.objectnames.push(objectnames);
|
||||
}
|
||||
});
|
||||
glob
|
||||
.sync(`${conf.dirtown}/tribes/${req.session.headers.xtribe}/schema/*.json`)
|
||||
.forEach((f) => {
|
||||
const objectname = path.basename(f, ".json");
|
||||
if (objectname == "conf") {
|
||||
data.apx.conf = fs.readJSONSync(f);
|
||||
} else {
|
||||
data.apx.objectnames.push(objectnames);
|
||||
}
|
||||
});
|
||||
res.status(200).json({ status: 200, ref: "Odmdb", msg: "objectslist", data });
|
||||
});
|
||||
/**
|
||||
* @api {get} /odmdb/idx/:tribe/:objectname/:indexname - index Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get index file for an object
|
||||
*
|
||||
* @apiParam {string} tribe if common adminapi or tribename
|
||||
* @apiParam {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname
|
||||
* @apiParam {String} indexname name of index file in /idx/indexnamme.json
|
||||
*
|
||||
@@ -32,39 +71,37 @@ const router = express.Router();
|
||||
*
|
||||
*
|
||||
*/
|
||||
router.get(
|
||||
"/idx/:objectname/:indexname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("passe");
|
||||
// indexname = objectname_key_value.json
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(req.params.objectname)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/`;
|
||||
// check if accessright
|
||||
}
|
||||
const indexpath = `${objectLocation}/${req.params.objectname}/idx/${req.params.indexname}`;
|
||||
if (fs.existsSync(indexpath)) {
|
||||
res
|
||||
.status(200)
|
||||
.json({
|
||||
ref: "Odmdb",
|
||||
msg: "indexexist",
|
||||
data: {
|
||||
indexname: req.params.indexname,
|
||||
content: fs.readJsonSync(indexpath),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath },
|
||||
});
|
||||
}
|
||||
router.get(
|
||||
"/idx/:tribe/:objectname/:indexname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("passe");
|
||||
// indexname = objectname_key_value.json
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(req.params.objectname)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/`;
|
||||
// check if accessright
|
||||
}
|
||||
);
|
||||
const indexpath = `${objectLocation}/${req.params.objectname}/idx/${req.params.indexname}`;
|
||||
if (fs.existsSync(indexpath)) {
|
||||
res.status(200).json({
|
||||
ref: "Odmdb",
|
||||
msg: "indexexist",
|
||||
data: {
|
||||
indexname: req.params.indexname,
|
||||
content: fs.readJsonSync(indexpath),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath },
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/rebuildidx/:objectname - index refresh all
|
||||
@@ -75,7 +112,7 @@ const router = express.Router();
|
||||
* @apiParam {string} objectname Mandatory
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* @apiSuccessExample {json} successreindex
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"successreindex", "data":{"indexlist":[]}}
|
||||
*
|
||||
@@ -85,58 +122,56 @@ const router = express.Router();
|
||||
{"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||
*
|
||||
*/
|
||||
router.get(
|
||||
"/rebuildidx/:objectname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("reindex");
|
||||
// check validity and accessright
|
||||
const objectPathname = conf.api.nationObjects.includes(
|
||||
req.params.objectname
|
||||
)
|
||||
? `${conf.dirapi}/nationchains/${req.params.objectname}`
|
||||
: `${conf.dirtown}/tribes/${req.session.header.xtribe}/${req.params.objectname}`;
|
||||
//console.log(objectPathname);
|
||||
if (!fs.existsSync(objectPathname)) {
|
||||
res.status(404).json({
|
||||
status: 404,
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath: objectPathname },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("mayor")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "mayor" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("druid")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "druid" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const reindex = Odmdb.idxfromitm(objectPathname, "I", {}, {}, [], {});
|
||||
res.status(reindex.status).json(reindex);
|
||||
router.get(
|
||||
"/rebuildidx/:objectname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("reindex");
|
||||
// check validity and accessright
|
||||
const objectPathname = conf.api.nationObjects.includes(
|
||||
req.params.objectname
|
||||
)
|
||||
? `${conf.dirapi}/nationchains/${req.params.objectname}`
|
||||
: `${conf.dirtown}/tribes/${req.session.header.xtribe}/${req.params.objectname}`;
|
||||
//console.log(objectPathname);
|
||||
if (!fs.existsSync(objectPathname)) {
|
||||
res.status(404).json({
|
||||
status: 404,
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath: objectPathname },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if (
|
||||
conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("mayor")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "mayor" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("druid")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "druid" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const reindex = Odmdb.idxfromitm(objectPathname, "I", {}, {}, [], {});
|
||||
res.status(reindex.status).json(reindex);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {post} /odmdb/itm/:objectname - item Create
|
||||
@@ -144,22 +179,22 @@ const router = express.Router();
|
||||
* @apiName postItm
|
||||
* @apiPermission none
|
||||
* @apiDescription Add an new item (data) into a collection of objectname items. Before Check data integrity with the relevant schema.
|
||||
* Then create a new primarykey. For multilanguage return see nationchains/model/lg/Odmdb_xx.json.
|
||||
*
|
||||
* Then create a new primarykey. For multilanguage return see nationchains/model/lg/Odmdb_xx.json.
|
||||
*
|
||||
* @apiParam {string} objectname Place where to create new item, schema and version are available in /objectname/conf.json
|
||||
*
|
||||
*
|
||||
* @apiBody {Object} data must pass Checkjson.js with schema
|
||||
*
|
||||
*
|
||||
* @apiSuccess {json} data idxprimary Value of idxprimary into objectname collection
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"cudsuccessfull", "data":{"itm":{}}}
|
||||
*
|
||||
*
|
||||
* @apiError {json} schemanotfound The objectname schema is not found
|
||||
* @apiError {json} pathnamedoesnotexist The objectname does not exist for the tribe
|
||||
* @apiError {json} missingprimarykey Body data must have primarykey to be created
|
||||
* @apiError {json} unconsistencyapxidx some Body data get unique key that already exist
|
||||
* @apiError {json} checkjsonfalse The body data are not consistent with the schema
|
||||
* @apiError {json} unconsistencyapxidx some Body data get unique key that already exist
|
||||
* @apiError {json} checkjsonfalse The body data are not consistent with the schema
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||
@@ -168,7 +203,7 @@ const router = express.Router();
|
||||
router.post("/itm/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
// Create an item of an object with no specificities
|
||||
// if specificities then create a route / model that import odmdb
|
||||
res.json({})
|
||||
res.json({});
|
||||
});
|
||||
router.get(
|
||||
"/searchitems/:objectname/:question",
|
||||
@@ -246,14 +281,14 @@ router.get(
|
||||
}
|
||||
);
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/Checkjson.js - schema check data lib
|
||||
* @api {get} https://wall-ants.ndda.fr/Checkjson.js - schema Checkjson.js
|
||||
* @apiGroup Odmdb
|
||||
* @apiName checkjsonjs
|
||||
* @apiDescription Public js lib to import in a browser by :<br>
|
||||
* ```<script src="wall-ants.ndda.fr/nationchains/contracts/Checkjson.js"></script>```
|
||||
* to import in a node.js:<br>
|
||||
* ```const Checkjson = require(`Checkjson.js`);```
|
||||
*
|
||||
*
|
||||
* with functions:<br>
|
||||
* <strong>Checkjson.schema.validation(schema)</strong> that return<br>
|
||||
* - {status:200, ref:"Checkjson", msg:"validcheck"} => all rules are correct<br>
|
||||
@@ -262,14 +297,12 @@ router.get(
|
||||
* <strong>Checkjson.schema.data(schema{json},data{json},withschemacheck{boolean})</strong> that return<br>
|
||||
* - {status:200, ref:"Checkjson", msg:"validcheck"} => all data keys respect schema rules <br>
|
||||
* - {status:417, multimsg:[{ref:"Checkjson",msg:"errorkey",data:{}}]}<br>
|
||||
*
|
||||
*
|
||||
* To identify issues, get the language errorkey list with a get
|
||||
* https://wall-ants.ndda.fr/nationchains/models/Checkjson_lg.json
|
||||
*
|
||||
* https://wall-ants.ndda.fr/nationchains/models/Checkjson_lg.json
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/schema/:objectname - schema Get public
|
||||
* @apiGroup Odmdb
|
||||
@@ -331,43 +364,170 @@ router.get(
|
||||
**/
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/schema/:objectname - schema Get private
|
||||
* @api {get} https://tribedns/:tribe/schema/:objectname.json - schema Get from tribe
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPrivateSchema
|
||||
* @apiDescription Get a private (profil must have accessright R on object) to a Schema model
|
||||
* @apiDescription Get a tribe schema or schema/lg/:objectname_xx.json this is served by nginx not express. tribedns is the domain name (ex:smatchit.io)
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory
|
||||
* @apiParam {string} tribe where schema is stored ex;smatchit
|
||||
* @apiParam {String} objectname the json file name ex persons.json or for language /lg/persons_fr.json
|
||||
*
|
||||
* @apiError {object} ref objectmodel to get in the right language
|
||||
* @apiError {object} ref objectname note found
|
||||
* @apiErrorExample {json} Error-response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"schemanotfound","data":{"fullpath"}}
|
||||
*
|
||||
* @apiSuccess {object} data contains schema requested
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* <html>...</html>
|
||||
* @apiSuccess {json} data contains schema requested
|
||||
* @apiSuccessExample {json} Success-Response for : https://smatchit.io/smatchit/schema/persons.json
|
||||
* HTTP/1.1 200 Success-response:
|
||||
* {"status":200,"data":{schema}}
|
||||
*/
|
||||
router.get("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const fullpath = path.resolve(
|
||||
`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`
|
||||
);
|
||||
if (fs.existsSync(fullpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(fullpath) });
|
||||
} else {
|
||||
res
|
||||
.status(404)
|
||||
.json({ status:404, msg: "schemanotfound", ref: "odmdb", data: { fullpath } });
|
||||
* {{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "/smatchit/schema/sirets",
|
||||
"title": "Siret is a legal french company",
|
||||
"description": "A recruiter can active a jobad if a maxnumber is not reach for this siret. Maxnumber is set depending of an offer or can be set manualy",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"siret": {
|
||||
"title": "siret",
|
||||
"description": "A unique string identifying a company ",
|
||||
"type": "string",
|
||||
"minLength": 14,
|
||||
"pattern": "^[0-9]*$"
|
||||
},
|
||||
"owner": {
|
||||
"title": "Owner of this siret",
|
||||
"description": "For accessright purpose this is set by the alias that pay the first time a subscription",
|
||||
"type": "string"
|
||||
},
|
||||
"dt_create": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"default": "dayjs.now()"
|
||||
},
|
||||
"dt_update": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"subscription": {
|
||||
"title": "Offer subscribe",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"offer": { "type": "string", "enum": ["A", "B", "C", "FREE"] },
|
||||
"dt_payment": { "type": "string", "format": "date-time" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"emailbilling":{
|
||||
"type":"string",
|
||||
"format":"email"
|
||||
},
|
||||
"namebilling":{
|
||||
"type":"string"
|
||||
},
|
||||
"maxactivejobad": {
|
||||
"title": "Number of active jobad at the same time",
|
||||
"description": "Alloaw by subscription payment for a date inside the last dt_payment and offer",
|
||||
"type": "integer"
|
||||
},
|
||||
"activejobad": {
|
||||
"title": "Current number of active jobadd",
|
||||
"type": "integer"
|
||||
},
|
||||
"frenchlocation": {
|
||||
"title": "Location",
|
||||
"description": "use franch gov refential to locaize",
|
||||
"$ref": "nationchains/schema/frenchlocation"
|
||||
},
|
||||
"denomination": {
|
||||
"title": "Company name",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["siret"],
|
||||
"additionalProperties": true,
|
||||
"apxid": "siret",
|
||||
"apxuniquekey": ["siret"],
|
||||
"apxidx": [
|
||||
{
|
||||
"name": "lst_siret",
|
||||
"keyval": "siret"
|
||||
}
|
||||
],
|
||||
"apxaccessrights": {
|
||||
"owner": {
|
||||
"D": [],
|
||||
"R": [
|
||||
"siret",
|
||||
"dt_create",
|
||||
"dt_update",
|
||||
"subscription",
|
||||
"maxactivejobadd",
|
||||
"activejobadd",
|
||||
"frenchlocation",
|
||||
"demomination"
|
||||
],
|
||||
"U": ["frenchlocation", "demomination"]
|
||||
},
|
||||
"druid": {
|
||||
"C": [],
|
||||
"D": [],
|
||||
"R": [
|
||||
"siret",
|
||||
"dt_create",
|
||||
"dt_update",
|
||||
"subscription",
|
||||
"maxactivejobadd",
|
||||
"activejobadd",
|
||||
"frenchlocation",
|
||||
"demomination"
|
||||
],
|
||||
"U": [
|
||||
"subscription",
|
||||
"maxactivejobadd",
|
||||
"activejobadd",
|
||||
"frenchlocation",
|
||||
"demomination"
|
||||
]
|
||||
},
|
||||
"pagans": { "C": [] },
|
||||
"adminrecruiter": {
|
||||
"C": [],
|
||||
"R": [
|
||||
"siret",
|
||||
"dt_create",
|
||||
"dt_update",
|
||||
"subscription",
|
||||
"maxactivejobadd",
|
||||
"activejobadd",
|
||||
"frenchlocation",
|
||||
"demomination"
|
||||
],
|
||||
"U": ["frenchlocation", "demomination"]
|
||||
},
|
||||
"recruiter": {
|
||||
"R": [
|
||||
"siret",
|
||||
"dt_create",
|
||||
"dt_update",
|
||||
"subscription",
|
||||
"maxactivejobadd",
|
||||
"activejobadd",
|
||||
"frenchlocation",
|
||||
"demomination"
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
}}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {put} /odmdb/schema/:objectname - schema Put
|
||||
* @api {put} https://wall-ants.ndda.fr/odmdb/schema/:tribe/:objectname - schema Put
|
||||
* @apiGroup Odmdb
|
||||
* @apiName putSchema
|
||||
* @apiDescription Replace a schema by another one need druid profil for a tribe
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory
|
||||
* @apiParam {String} objectname
|
||||
*
|
||||
* @apiBody {string} schemapath where to store schema .../schema
|
||||
* @apiBody {string} objectpath where to store object ...objectname/idx/conf.json
|
||||
@@ -386,23 +546,27 @@ router.get("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
*
|
||||
*
|
||||
*/
|
||||
router.put("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const fullpath = path.resolve(
|
||||
`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`
|
||||
);
|
||||
const set = Odmdb.setObject(
|
||||
path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}`)
|
||||
);
|
||||
router.put(
|
||||
"schema/:tribe/:objectname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
const fullpath = path.resolve(
|
||||
`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`
|
||||
);
|
||||
const set = Odmdb.setObject(
|
||||
path.resolve(`${__dirname}/tribes/${req.session.header.xworkon}`)
|
||||
);
|
||||
|
||||
if (fs.existsSync(fullpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(fullpath) });
|
||||
} else {
|
||||
res
|
||||
.status(404)
|
||||
.json({ msg: "schemanotfound", ref: "odmdb", data: { fullpath } });
|
||||
if (fs.existsSync(fullpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(fullpath) });
|
||||
} else {
|
||||
res
|
||||
.status(404)
|
||||
.json({ msg: "schemanotfound", ref: "odmdb", data: { fullpath } });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/models/:modelname_lg.json - translation notif Get public
|
||||
|
@@ -1,14 +1,15 @@
|
||||
const express = require("express");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
// Classes
|
||||
const Pagans = require("../models/Pagans.js");
|
||||
|
||||
const Odmdb = require("../models/Odmdb.js");
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
|
||||
const conf = require(`${process.env.dirtown}/conf.json`);
|
||||
|
||||
const router = express.Router();
|
||||
/**
|
||||
* /api/models/Pagans.js
|
||||
@@ -44,8 +45,8 @@ router.get("/alias/:alias", (req, res) => {
|
||||
* @api {get} /pagans/logout - pagan Logout
|
||||
* @apiName Removetoken
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Remove token
|
||||
*
|
||||
* @apiDescription Remove token
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
@@ -101,6 +102,12 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
* - xhash is well signed from private key linked to the publickey of alias
|
||||
* - check that alias does not already exist (if yes then verifiedsigne would be false)
|
||||
* Need to wait next block chain to be sure that alias is register in the blokchain
|
||||
* @apiBody {string} alias available (that does not already exist check get /api/alias/:alias that must return 404).
|
||||
* @apiBody {string} publickey
|
||||
* @apiBody {string} [email] if specified then an email is sent to it with public and privatekey
|
||||
* @apiBody {string} [privatekey]
|
||||
* @apiBody {string} [passphrase] if not specidied => passphrase=""
|
||||
* @apiBody {string} [trustedtribe] the tribename if not specified then the process will only create a pagan identity, else an item person is create for trustedtribe (that must exist with profil 'person'). To create a person with an existing pagan identity use put /api/person/:alias after authenticated you (headers). In case a person is created then we use all valid other apiBody respecting rules https://smatchit.io/api/odmdb/schema/persons.json
|
||||
*
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
@@ -113,42 +120,64 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
|
||||
*
|
||||
*/
|
||||
router.post("/", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log("pass ici", req.body);
|
||||
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
|
||||
const newpagan = Pagans.create(objpagan, {
|
||||
router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
||||
console.log("pass ici", req.body);
|
||||
const role = {
|
||||
xalias: req.session.header.xalias,
|
||||
xprofils: req.session.header.xprofils,
|
||||
});
|
||||
};
|
||||
const emailregex =
|
||||
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if (!(req.body.trustedtribe && req.body.email && emailregex.test(req.body.email) )) {
|
||||
res.status(400).json({status:400,ref:"Pagans",msg:"emailerr", data:{email:req.body.email}})
|
||||
return
|
||||
}
|
||||
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
|
||||
const newpagan = Odmdb.cud(`${conf.dirapi}/nationchains/pagans`, "C", objpagan, role);
|
||||
const createprocess={status:200, ref:"Pagans", msg:"successfulcreate",data:{alias:req.body.alias}};
|
||||
if (newpagan.status == 200) {
|
||||
if (req.body.email) {
|
||||
const emailsent = Pagans.sendmailkey(
|
||||
const emailsent = await Pagans.sendmailkey(
|
||||
req.body.alias,
|
||||
req.body.privatekey,
|
||||
req.session.header.xtribe,
|
||||
req.body.passphrase,
|
||||
req.body.publickey,
|
||||
req.body.email
|
||||
req.body.email,
|
||||
req.session.header.xlang
|
||||
);
|
||||
createprocess.data.emailsent = (emailsent.status == 200);
|
||||
createprocess.data.email=req.body.email
|
||||
createprocess.data.tribe=req.session.header.xtribe;
|
||||
if (emailsent.status!=200) {
|
||||
console.log("err emailsent: ",emailsent)
|
||||
createprocess.data.emailerror = emailsent.data.err;
|
||||
}
|
||||
}
|
||||
if (req.body.trustedtribe) {
|
||||
const personup = Pagans.personupdate(
|
||||
req.body.alias,
|
||||
req.body.trustedtribe,
|
||||
{
|
||||
recoveryauth: {
|
||||
email: req.body.email,
|
||||
privatekey: req.body.privatekey,
|
||||
publickey: req.body.publickey,
|
||||
passphrase: req.body.passphrase,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (personup.status !== 200)
|
||||
console.log("Warning no recovery registration", personup);
|
||||
}
|
||||
if (emailsent && emailsent.status != 200) {
|
||||
newpagan.msg = "successfulcreatewithoutemail";
|
||||
const persondata = {
|
||||
alias: req.body.alias,
|
||||
owner: req.body.alias,
|
||||
profils: ["pagans", "persons"],
|
||||
recoveryauth: {
|
||||
email: req.body.email,
|
||||
privatekey: req.body.privatekey,
|
||||
publickey: req.body.publickey,
|
||||
passphrase: req.body.passphrase,
|
||||
},
|
||||
};
|
||||
const personup = Odmdb.cud(`${conf.dirtown}/tribes/${req.body.trustedtribe}/objects/persons`, "C", persondata, {xprofils:["pagan"],xalias:req.body.alias});
|
||||
console.log('personup',personup)
|
||||
if (personup.status==200){
|
||||
createprocess.data.createperson=true;
|
||||
}else{
|
||||
createprocess.data.createperson=false;
|
||||
createprocess.data.errorperson=true;
|
||||
createprocess.data.errpersonup=personup.data;
|
||||
console.log("Warning pagan created but person not created and no recovery registration", personup);
|
||||
}
|
||||
res.status(createprocess.status).json(createprocess);
|
||||
}else{
|
||||
res.status(newpagan.status).json(newpagan);
|
||||
}
|
||||
} else {
|
||||
@@ -161,31 +190,45 @@ router.post("/", checkHeaders, isAuthenticated, (req, res) => {
|
||||
* @apiName deletepagan
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* Delete an alias and his publickey
|
||||
* Delete an alias and his publickey, this mean that publickey disapear as well as alias. All tribe will be inform and will delete person of this alias if they have. This alias will be availlable after 1 year.
|
||||
* */
|
||||
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deletealias(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
res.status(result.status).send(result);
|
||||
});
|
||||
/**
|
||||
* @api {delete} /pagans/person/:alias - person Delete
|
||||
* @apiName deleteperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* Unsubscribe a person to a tribe => remove a person item and all data link to this alias
|
||||
* */
|
||||
router.delete("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deleteperson(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
const personpath=`${conf.dirtown}/tribes/${req.session.header.xtribe}/objects/persons`;
|
||||
const role = {
|
||||
xalias: req.session.header.xalias,
|
||||
xprofils: req.session.header.xprofils,
|
||||
};
|
||||
req.session.header.role
|
||||
const delperson = Odmdb.cud(personpath,"D",{alias:req.params.alias},role,true);
|
||||
console.log(`DELETE person ${personpath}/${req.params.alias}.json `);
|
||||
console.log(delperson)
|
||||
res.status(delperson.status).json(delperson);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/person:alias - person Get
|
||||
* @api {get} /pagans/person/:alias - person Get
|
||||
* @apiName getpersondata
|
||||
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
||||
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
||||
* @apiGroup Pagans
|
||||
*
|
||||
* @apiParam {string} alias
|
||||
*
|
||||
*
|
||||
* @apiSuccess (200) personExist
|
||||
* @apiSuccessExample {json}
|
||||
* {status:200, ref:"pagans",msg:"personexist",data: { person } }
|
||||
*
|
||||
*
|
||||
* @apiError (404) Notfound
|
||||
* @apiErrorExample {json}
|
||||
* {status: 404, ref:"pagans",msg:"persondoesnotexist",data: { person } }
|
||||
@@ -195,57 +238,32 @@ router.delete("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
* else need accessright to on person set at R
|
||||
* */
|
||||
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const getperson = Pagans.getperson(
|
||||
req.session.header.xtribe,
|
||||
req.params.alias,
|
||||
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
|
||||
);
|
||||
const getperson=Odmdb.r( `${conf.dirtown}/tribes/${req.session.header.xtribe}/objects/persons`,req.params.alias,{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias })
|
||||
res.status(getperson.status).send(getperson);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {post} /pagans/person - person Post
|
||||
* @apiName addperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* add a person = alias + tribe with specific accessright and specific schema link to tribe
|
||||
*
|
||||
*
|
||||
*
|
||||
* @todo add tribe/schema/person.json
|
||||
*/
|
||||
router.post("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log(req.body);
|
||||
const persoad = Pagans.personcreate(
|
||||
req.session.header.xtribe,
|
||||
req.body.alias,
|
||||
req.body,
|
||||
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
|
||||
);
|
||||
res.status(persoad.status).json(persoad);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {put} /pagans/person - person Put
|
||||
* @apiName updateperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* update a person = alias + tribe with specific accessright and specific schema link to tribe
|
||||
|
||||
* @todo add tribe/schema/person.json
|
||||
* @apiDescription add or update a person = alias in a tribe. alias authenticated must have a profil with accessright into schema person.
|
||||
* @apiHeader {string} xalias
|
||||
* @apiParam {object} in line with schema in https://smatchit.io/api/odmdb/schema/persons
|
||||
*
|
||||
*/
|
||||
router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log(req.body);
|
||||
const persoup = Pagans.personupdate(
|
||||
req.session.header.xtribe,
|
||||
req.body.alias,
|
||||
req.body,
|
||||
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
|
||||
);
|
||||
res.status(persoup.status).json(persoup);
|
||||
const pathobj=`${conf.dirtown}/tribes/${req.session.header.xtribe}/objects/persons`;
|
||||
const action = (fs.existsSync(`${pathobj}/itm/${req.body.alias}.json`))? "U":"C";
|
||||
//set req.body to be in line with schema
|
||||
if (!req.body.profils){
|
||||
req.body.profils=["anonymous","pagans","persons"]
|
||||
}
|
||||
const personup = Odmdb.cud(pathobj, action, req.body, {xprofils:req.session.header.xprofils, xalias:req.session.header.xalias});
|
||||
console.log('personup',personup)
|
||||
res.status(personup.status).json(personup);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/keyrecovery/tribe/email - recovery key by email
|
||||
* @apiName recoveryKey
|
||||
|
@@ -8,161 +8,25 @@ const Notifications = require("../models/Notifications.js");
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
/*
|
||||
|
||||
*/
|
||||
router.get("/changeowner/:alias",checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {get} /towns/ownershipr/:alias
|
||||
* @apiName Change owner of a town mayorId
|
||||
* @apiGroup Pagans
|
||||
/**
|
||||
* @api {get} /towns/ownershipr/:alias - town owner change
|
||||
* @apiName changeowner
|
||||
* @apiGroup Towns
|
||||
* @apiDescription Change owner (major role) of a town (server) after a first install or just to resale it. Only the current major can run this.
|
||||
* @param {string} alias an alias that will become owner of a town
|
||||
* @apiSuccess (200) {object} {ref:"towns",msg:"ownerchangesuccess",data: { alias } }
|
||||
* @apiError (404) {object} {ref:"towns",msg:"aliasnotallow",data: { alias} }
|
||||
* @apiSuccess (object) ownerchangesuccess
|
||||
* @apiSuccessExample {json}
|
||||
* HTTP/1.1 200 OK
|
||||
* {status:200, ref:"towns",msg:"ownerchangesuccess",data: { alias } }
|
||||
* @apiError {object} aliasnotallow
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 403 Forbidden
|
||||
* {status:403,ref:"towns",msg:"aliasnotallow",data: { alias} }
|
||||
*
|
||||
**/
|
||||
router.get("/changeowner/:alias",checkHeaders, isAuthenticated, (req, res) => {
|
||||
res.send(Towns.changeowner(req.params.alias, req.session.header.xalias));
|
||||
});
|
||||
|
||||
//=======================================================================================
|
||||
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {get} /pagans/person:alias
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
* @param {string} alias that exist
|
||||
* @param {string} tribeId that exist with a person alias
|
||||
* @apiSuccess (200) {ref:"pagans",msg:"personexist",data: { person } }
|
||||
* @apiError (404) {ref:"pagans",msg:"persondoesnotexist",data: { person } }
|
||||
*
|
||||
* @todo check accessright for req.session.header.xalias to see if jhe can get person data
|
||||
* if req.param.alias == req.session.header.xalias => Owner
|
||||
* else need accessright to on person set at R
|
||||
* */
|
||||
res.send(Pagans.getperson(req.params.alias, req.session.header.xtribe));
|
||||
});
|
||||
|
||||
router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {get} /pagans/isauth
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiError (400) {object} status missingheaders / xalias does not exist / signaturefailled
|
||||
* @apiError (401) {object} alias anonymous (not authenticated)
|
||||
* @apiError (404) {string} tribe does not exist
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
*
|
||||
*/
|
||||
res.send({
|
||||
status: 200,
|
||||
ref: "headers",
|
||||
msg: "authenticated",
|
||||
data: {
|
||||
xalias: req.session.header.xalias,
|
||||
},
|
||||
});
|
||||
});
|
||||
router.post("/", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {post} /pagans
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* Create a pagan account from alias, publickey, if trusted recovery =>
|
||||
* Create a person in xtribe/person/xalias.json with profil.auth={email,privatekey, passphrase}
|
||||
* Middleware isAuthenticated check that:
|
||||
* - xhash is well signed from private key linked to the publickey of alias
|
||||
* - check that alias does not already exist (if yes then verifiedsigne would be false)
|
||||
* Need to wait next block chain to be sure that alias is register in the blokchain
|
||||
*/
|
||||
console.log("pass ici", req.body);
|
||||
const feedback = { alias: req.body.alias, publickey: req.body.publickey };
|
||||
const newpagan = Pagans.create(req.body.alias, req.body.publickey);
|
||||
if (newpagan.status == 200) {
|
||||
if (req.body.email) {
|
||||
feedback.withemail = true;
|
||||
feedback.email = req.body.email;
|
||||
feedback.privatekey = req.body.privatekey;
|
||||
feedback.passphrase = req.body.passphrase;
|
||||
Notifications.send({
|
||||
type: "email",
|
||||
from: "",
|
||||
dest: [req.body.email],
|
||||
tpl: "registeremail",
|
||||
tribe: req.session.header.xtribe,
|
||||
data: feedback,
|
||||
});
|
||||
}
|
||||
if (req.body.trustedtribe) {
|
||||
if (req.app.locals.tribeids.includes(req.body.trustedtribe)) {
|
||||
delete feedback.withemail;
|
||||
const persondata = { recovery: feedback };
|
||||
res.send(
|
||||
Pagans.personupdate(req.body.alias, req.body.trustedtribe, persondata)
|
||||
);
|
||||
} else {
|
||||
res.send({
|
||||
status: 404,
|
||||
ref: "Pagans",
|
||||
msg: "tribedoesnotexist",
|
||||
data: { tribe: req.body.trustedtribe },
|
||||
});
|
||||
}
|
||||
} else {
|
||||
newpagan.data = feedback;
|
||||
res.send(newpagan);
|
||||
}
|
||||
} else {
|
||||
//error to create pagan
|
||||
res.send(newpagan);
|
||||
}
|
||||
});
|
||||
router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {put} /pagans/person
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* add/update a person = alias + tribe with specific accessright and specific schema link to tribe
|
||||
* @todo add tribe/schema/person.json
|
||||
*/
|
||||
console.log(req.body);
|
||||
res.send(
|
||||
Pagans.personupdate(req.body.alias, req.session.header.xtribe, req.body)
|
||||
);
|
||||
});
|
||||
router.delete("/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {delete} /pagans/:alias
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
* */
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.delete(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
});
|
||||
router.get("/keyrecovery/:tribeid/:email", checkHeaders, (req, res) => {
|
||||
/**
|
||||
* @api {get} /pagans/keyrecovery/tribe/email
|
||||
* @apiName apxtrib
|
||||
* @apiGroup Pagans
|
||||
*
|
||||
*
|
||||
*
|
||||
* @apiError (400) {object} status missingheaders / xalias does not exist / signaturefailled
|
||||
* @apiError (401) {object} alias anonymous (not authenticated)
|
||||
* @apiError (404) {string} tribe does not exist
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
*
|
||||
*/
|
||||
res.send(Pagans.keyrecovery(req.params.tribeId, req.params.email));
|
||||
});
|
||||
module.exports = router;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
const express = require( 'express' );
|
||||
const fs = require( 'fs-extra' );
|
||||
const path = require( 'path' );
|
||||
const glob = require('glob');
|
||||
const conf = require(`${process.env.dirtown}/conf.json`);
|
||||
|
||||
// Classes
|
||||
@@ -10,25 +11,24 @@ const checkHeaders = require( '../middlewares/checkHeaders' );
|
||||
const isAuthenticated = require( '../middlewares/isAuthenticated' );
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} /tribes/www/:tribeId - tribe list
|
||||
* @apiName getlisttrib
|
||||
* @apiDescription Get list of www object (space web)
|
||||
* @apiGroup Tribes
|
||||
*
|
||||
* @apiParam {String} tribeId it identify an existing tribe*
|
||||
* @apiSuccess (object) listwww contains folder name in www for tribeId
|
||||
* @apiSuccessExample {json} listwww
|
||||
* HTTP/1.1 200 OK
|
||||
* {status:200,ref:"Tribes",msg:"listwww",data:{listwww}}
|
||||
*/
|
||||
router.get('www', checkHeaders,isAuthenticated,(req,res)=>{
|
||||
/**
|
||||
* @api {get} /tribes/www/:tribeId
|
||||
* @apiName Get list of www object (space web)
|
||||
* @apiGroup Tribes
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiParam {String} tribeId Mandatory it identify an existing tribe
|
||||
* @apiParam {String} Check if Person has access as Read to object www
|
||||
* @apiError (404) {string} status the file does not exist
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
*/
|
||||
res.status(200).json({data:{}})
|
||||
let listwww=[]
|
||||
glob.sync(`${conf.dirtown}/tribes/${req.params.tribeId}/www/*`).forEach(d=>{
|
||||
listwww.push(d.split("/").pop())
|
||||
})
|
||||
res.status(200).json({status:200,ref:"Tribes",msg:"listwww",data:{listwww}})
|
||||
})
|
||||
|
||||
//router.post('www/') to create a webspace
|
||||
|
@@ -8,39 +8,12 @@ const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* To manage an nginx conf
|
||||
*
|
||||
*/
|
||||
|
||||
router.get("/tribes/:tribeId", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {get} /www/tribes/:tribeId
|
||||
* @apiName Get list of application Name
|
||||
* @apiGroup Www
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiParam {String} tribeId Mandatory that have to exist in current town and
|
||||
*
|
||||
* @apiError (404) {string} status the folder does not exist
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to www's model: 'Www' } );render lg/objectmodel_lg.json
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains liste of www conf of a tribe
|
||||
*
|
||||
*/
|
||||
|
||||
// GET api/wwws/conf/:tribeId/:website
|
||||
// if profils accessright return the nginx conf in ${conf.dirtown}/tribes/${req.param.tribeId}/www/nginx_${req.params.tribeId}_${req.params.website}.conf
|
||||
router.get("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => {
|
||||
res.send(Www.configlist(req.params.tribeId));
|
||||
});
|
||||
router.post("/:webappname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* Create a space web /tribes/www/webappname
|
||||
*
|
||||
*
|
||||
* */
|
||||
router.post("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => {
|
||||
res.send(Wwws.create(req.params.tribeId));
|
||||
});
|
||||
module.exports = router;
|
||||
|
Reference in New Issue
Block a user