modif archi apxtri
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const express = require( 'express' );
|
||||
const fs=require('fs-extra');
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
const conf = require(`../../../../conf/townconf.json`);
|
||||
|
||||
// Classes
|
||||
const Nations = require( '../models/Nations.js' );
|
||||
@@ -17,7 +17,7 @@ Manage a new towns in a nation => update nation:[nationname:towns:[]} contracts/
|
||||
|
||||
|
||||
/**
|
||||
* @api {put} /nations/viewtown/:town - nationlist from a town major
|
||||
* @api {put} adminapi/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
|
||||
|
@@ -26,7 +26,7 @@ router.post("/backend", (req, res) => {
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {get} /notifications/:alias/:tribeId
|
||||
* @api {get} adminapi/notifications/:alias/:tribeId
|
||||
* @apiName notiflist
|
||||
* @apiDescription Get list of notifications for an alias and a tribe
|
||||
* @apiGroup Notifications
|
||||
@@ -46,15 +46,15 @@ router.get("/:alias/:tribeId", (req, res) => {
|
||||
|
||||
|
||||
/**
|
||||
* @api {POST} /notifications/registeranonymous/:tribe/:mlist/:typekey/:data -Contact anonymous
|
||||
* @api {POST} adminapi/notifications/registeranonymous/:tribe/:mlist/:typekey/:data -Register email||phone to mlist
|
||||
* @apiName register
|
||||
* @apiGroup Notifications
|
||||
* @apiDescription Register an email into a mailinglist mlist
|
||||
* @apiDescription Register an email or phone into a mailinglist mlist
|
||||
* @apiBody {string} tribe an existing tribe
|
||||
* @apiBody {string} mlist a mailing list name
|
||||
* @apiBody {string} key email or phone
|
||||
* @apiBody {string} key email or phone keyword
|
||||
* @apiBod {string} srckey must exist in tribes/schema/lg/enumtrk_xx.json
|
||||
* @apiParams {string} data the email or phone
|
||||
* @apiParams {string} data the email or phone value
|
||||
* @apiSuccess {object} update mailinglist/{mlist}.json successfull
|
||||
* @apiSuccessExample {json} successfullmessage
|
||||
* HTTP/1.1 200 OK
|
||||
@@ -77,8 +77,8 @@ router.post("/registeranonymous",checkHeaders,(req,res)=>{
|
||||
res.status(result.status).json(result)
|
||||
})
|
||||
/**
|
||||
* @api {GET} /notifications/unregister/:tribe/:mlist/:typekey/:data/:validation -Contact anonymous
|
||||
* @apiName contactanonymous
|
||||
* @api {GET} adminapi/notifications/unregister/:tribe/:mlist/:typekey/:data/:validation -Unregister email o r phone from a mlist or all mlist
|
||||
* @apiName unregister
|
||||
* @apiGroup Notifications
|
||||
* @apiDescription Register an email into a mailinglist mlist
|
||||
* @apiParams {string} tribe an existing tribe
|
||||
@@ -94,7 +94,7 @@ router.post("/registeranonymous",checkHeaders,(req,res)=>{
|
||||
*
|
||||
*/
|
||||
|
||||
router.get("/unregisteranonymous/:tribe/:mlist/:typekey/:srckey/:data/:validation", checkHeaders, (req, res) => {
|
||||
router.get("/unregister/:tribe/:mlist/:typekey/:srckey/:data/:validation", checkHeaders, (req, res) => {
|
||||
Notifications.registertolist = (typekey, tribe, mlist, srckey, uuid)
|
||||
result= Notifications.registertolist(
|
||||
req.params.typekey,
|
||||
@@ -106,7 +106,7 @@ router.get("/unregisteranonymous/:tribe/:mlist/:typekey/:srckey/:data/:validatio
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {POST} /notifications/contactanonymous/:tribe -Contact anonymous
|
||||
* @api {POST} adminapi/notifications/contactanonymous/:tribe -Contact anonymous
|
||||
* @apiName contactanonymous
|
||||
* @apiGroup Notifications
|
||||
* @apiDescription Register a contact in tribe and send a mail to admin of tribe
|
||||
|
@@ -2,7 +2,7 @@ const express = require("express");
|
||||
const glob = require("glob");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
const conf = require(`../../../../conf/townconf.json`);
|
||||
const Odmdb = require("../models/Odmdb.js");
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders.js");
|
||||
@@ -10,46 +10,71 @@ const isAuthenticated = require("../middlewares/isAuthenticated.js");
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/objects - objects Get
|
||||
* @api {get} adminapi/odmdb/schemas - objects Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get objects available for header.xtribe
|
||||
* @apiDescription Get objects available result is store in data.apx.conf for schema conf of adminapi schema (pagans,towns,... ) and data.apx.objectnames as array of schema name. Schema related to tribe are store in data.tribe.conf and data.tribe.objectnames where tribe come from 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}}
|
||||
*
|
||||
*
|
||||
* {"status":200, "ref":"Odmdb", "msg":"objectslist", "data":{apx:{conf,objectnames:[]},tribe:{conf,objectnames:[]}}}
|
||||
*/
|
||||
router.get("/objects", checkHeaders, isAuthenticated, (req, res) => {
|
||||
router.get("/schemas", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const data = {
|
||||
tribe: req.session.header.xtribe,
|
||||
apx: { conf: {}, objectnames: [] },
|
||||
tribe: { conf: {}, objectnames: [] },
|
||||
};
|
||||
glob.sync(`../nationchains/tribes/adminapi/schema/*.json`).forEach((f) => {
|
||||
glob.sync(`../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);
|
||||
data.apx.objectnames.push(objectname);
|
||||
}
|
||||
});
|
||||
glob
|
||||
.sync(`../nationchains/tribes/${req.session.header.xtribe}/schema/*.json`)
|
||||
.sync(`../../${req.session.header.xtribe}/schema/*.json`)
|
||||
.forEach((f) => {
|
||||
const objectname = path.basename(f, ".json");
|
||||
if (objectname == "conf") {
|
||||
data.apx.conf = fs.readJSONSync(f);
|
||||
data.tribe.conf = fs.readJSONSync(f);
|
||||
} else {
|
||||
data.apx.objectnames.push(objectnames);
|
||||
data.tribe.objectnames.push(objectname);
|
||||
}
|
||||
});
|
||||
res.status(200).json({ status: 200, ref: "Odmdb", msg: "objectslist", data });
|
||||
});
|
||||
/**
|
||||
* @api {get} /odmdb/idx/:tribe/:objectname/:indexname - index Get
|
||||
* @api {get} adminapi/odmdb/schema/:source/:objectname - Schema Get in the language header
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get schema in the requested language if login have accessright
|
||||
*
|
||||
* @apiParams {string} source (adminapi || tribe) looking for adminapi or in tribe (header.xtribe)
|
||||
* @apiParams {string} objectname requested must exist in adminapi or tribe
|
||||
* @apiSuccess {object} contain data.schema
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg}
|
||||
*/
|
||||
router.get("/schema/:source/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
if (!['adminapi','tribe'].includes(req.params.source)){
|
||||
res(406).json({status:406,ref:"Odmdb",msg:"mustbetribeoradminapi",data:{source:req.params.source}})
|
||||
}else{
|
||||
let objectPathname=`../../adminapi/objects/${req.params.objectname}`
|
||||
if (req.params.source=="tribe"){
|
||||
objectPathname=`../../${req.headers.xtribe}/objects/${req.params.objectname}`
|
||||
}
|
||||
console.log(objectPathname)
|
||||
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang)
|
||||
res.status(retschema.status).json(retschema);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get index file for an object
|
||||
@@ -104,7 +129,7 @@ router.get(
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/rebuildidx/:objectname - index refresh all
|
||||
* @api {get} adminapi/odmdb/rebuildidx/:objectname - index refresh all
|
||||
* @apiGroup Odmdb
|
||||
* @apiName refreshAllIndex
|
||||
* @apiDescription Rebuild all index for an object, this can be usefull in case crash or any data conflict.
|
||||
@@ -174,7 +199,7 @@ router.get(
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {post} /odmdb/itm/:objectname - item Create
|
||||
* @api {post} adminapi/odmdb/itm/:objectname - item Create
|
||||
* @apiGroup Odmdb
|
||||
* @apiName postItm
|
||||
* @apiPermission none
|
||||
@@ -233,12 +258,12 @@ router.get(
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/itm/:objectname/:primaryindex - item Get
|
||||
* @api {get} adminapi/odmdb/itm/:objectname/:primaryindex - item Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getItemFromId
|
||||
* @apiDescription Get itm for a primaryid of an object
|
||||
*
|
||||
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname
|
||||
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /tribes/xtribe/objectname
|
||||
* @apiParam {String} primaryindex the unique id where item is store
|
||||
*
|
||||
* @apiError {json} objectNotfound the file item does not exist
|
||||
@@ -281,11 +306,11 @@ router.get(
|
||||
}
|
||||
);
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/Checkjson.js - schema Checkjson.js
|
||||
* @api {get} https://wall-ants.ndda.fr/adminapi/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>```
|
||||
* ```<script src="https://wall-ants.ndda.fr/adminapi/Checkjson.js"></script>```
|
||||
* to import in a node.js:<br>
|
||||
* ```const Checkjson = require(`Checkjson.js`);```
|
||||
*
|
||||
@@ -299,12 +324,12 @@ router.get(
|
||||
* - {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
|
||||
* MUST BE UPDATE with conf access https://wall-ants.ndda.fr/adminapi/objects/tplstring/Checkjson_lg.json
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/schema/:objectname - schema Get public
|
||||
* @api {get} https://wall-ants.ndda.fr/adminapi/schema/:objectname - schema Get public
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPublicSchema
|
||||
* @apiDescription Get a Schema model from public apxtri (nations, pagans,persons,towns, tribes,wwws)
|
||||
@@ -312,7 +337,7 @@ router.get(
|
||||
* @apiSuccessExample {json} Fichier direct
|
||||
* HTTP/1.1 200 Success-response:
|
||||
{
|
||||
"$id": "https://smatchit.io/schema/pagan",
|
||||
"$id": "https://wall-ants.ndda.fr/schema/pagan",
|
||||
"$comment": "To create account bin apxtri",
|
||||
"title": "Pagans identity",
|
||||
"description": "A numeric id in the nationchains world",
|
||||
@@ -569,7 +594,7 @@ router.put(
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/models/:modelname_lg.json - translation notif Get public
|
||||
* @api {get} https://wall-ants.ndda.fr/adminapi/objects/tplstring/:modelname_lg.json - translation notif Get public
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPublicModelmessagekey
|
||||
* @apiDescription Get a public json object for the ref: modelname in language lg, to get a template description with key msg
|
||||
|
@@ -9,7 +9,7 @@ const Odmdb = require("../models/Odmdb.js");
|
||||
const checkHeaders = require("../middlewares/checkHeaders.js");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated.js");
|
||||
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
const conf = require(`../../../../conf/townconf.json`);
|
||||
const currentmod = "pagans";
|
||||
const log = conf.api.activelog.includes(currentmod);
|
||||
|
||||
@@ -21,7 +21,7 @@ const router = express.Router();
|
||||
|
||||
/**
|
||||
* Alias exist then return public key or not
|
||||
* @api {get} /pagans/alias/:alias - alias Get
|
||||
* @api {get} adminapi/pagans/alias/:alias - alias Get
|
||||
* @apiName isalias
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription If alias exist return its publickey
|
||||
@@ -44,7 +44,7 @@ router.get("/alias/:alias", (req, res) => {
|
||||
res.status(getalias.status).send(getalias);
|
||||
});
|
||||
/**
|
||||
* @api {get} /pagans/logout - pagan Logout
|
||||
* @api {get} adminapi/pagans/logout - pagan Logout
|
||||
* @apiName Removetoken
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Remove server's token only the owner of the token (no one else can delete a token )
|
||||
@@ -66,7 +66,7 @@ router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
||||
res.status(logout.status).json(logout);
|
||||
});
|
||||
/**
|
||||
* @api {get} /pagans/isauth - pagan isAuthenticated?
|
||||
* @api {get} adminapi/pagans/isauth - pagan isAuthenticated?
|
||||
* @apiName isAuth
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Check if pagan's token is still valid
|
||||
@@ -94,7 +94,7 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {post} /pagans - pagan Post
|
||||
* @api {post} adminapi/pagans - pagan Post
|
||||
* @apiName addpagan
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
@@ -137,7 +137,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
||||
return
|
||||
}
|
||||
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
|
||||
const newpagan = Odmdb.cud(`../nationchains/pagans`, "C", objpagan, role);
|
||||
const newpagan = Odmdb.cud(`../../objects/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) {
|
||||
@@ -171,7 +171,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
||||
passphrase: req.body.passphrase,
|
||||
},
|
||||
};
|
||||
const personup = Odmdb.cud(`../nationchains/tribes/${req.body.trustedtribe}/objects/persons`, "C", persondata, {xprofils:["pagan"],xalias:req.body.alias});
|
||||
const personup = Odmdb.cud(`../../${req.body.trustedtribe}/objects/persons`, "C", persondata, {xprofils:["pagan"],xalias:req.body.alias});
|
||||
if (log) console.log(currentmod,'person create',personup)
|
||||
if (personup.status==200){
|
||||
createprocess.data.createperson=true;
|
||||
@@ -191,14 +191,14 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
||||
}
|
||||
});
|
||||
/**
|
||||
* @api {delete} /pagans/alias/:alias - pagan Delete
|
||||
* @api {delete} adminapi/pagans/alias/:alias - pagan Delete
|
||||
* @apiName deletepagan
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* Delete an alias and his publickey, this mean that publickey disapear as well as alias. We set dt_delete
|
||||
* */
|
||||
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const personpath=`../nationchains/pagans`;
|
||||
const personpath=`../objects/pagans`;
|
||||
const role = {
|
||||
xalias: req.session.header.xalias,
|
||||
xprofils: req.session.header.xprofils,
|
||||
@@ -209,12 +209,12 @@ router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
if (log) console.log(delperson)
|
||||
res.status(delperson.status).json(delperson);
|
||||
|
||||
if (log) console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
if (log) console.log(`DELETE pagans adminapi/objects/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.delete(req.params.alias, req.session.header);
|
||||
res.status(result.status).send(result);
|
||||
});
|
||||
/**
|
||||
* @api {delete} /pagans/person/:tribe/:alias - person Delete
|
||||
* @api {delete} adminapi/pagans/person/:tribe/:alias - person Delete
|
||||
* @apiName deleteperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
@@ -225,7 +225,7 @@ router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
* @apiParam {string} alias to delete as person
|
||||
* */
|
||||
router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const personpath=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
|
||||
const personpath=`../../${req.params.tribe}/objects/persons`;
|
||||
const role = {
|
||||
xalias: req.session.header.xalias,
|
||||
xprofils: req.session.header.xprofils,
|
||||
@@ -238,7 +238,7 @@ router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res)
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/person/:alias - person Get
|
||||
* @api {get} adminapi/pagans/person/:alias - person Get
|
||||
* @apiName getpersondata
|
||||
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
||||
* @apiGroup Pagans
|
||||
@@ -258,12 +258,13 @@ router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res)
|
||||
* else need accessright to on person set at R
|
||||
* */
|
||||
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const getperson=Odmdb.r( `../nationchains/tribes/${req.session.header.xtribe}/objects/persons`,req.params.alias,{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias })
|
||||
console.log(path.resolve(`../../${req.session.header.xtribe}/objects/persons`))
|
||||
const getperson=Odmdb.r( `../../${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 {put} /pagans/person/:tribe - person Put
|
||||
* @api {put} adminapi/pagans/person/:tribe - person Put
|
||||
* @apiName updateperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
|
||||
@@ -275,7 +276,7 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
*/
|
||||
router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log(req.body);
|
||||
const pathobj=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
|
||||
const pathobj=`../../${req.params.tribe}/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){
|
||||
@@ -287,7 +288,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/keyrecovery/:tribe/:email - recovery keys by email
|
||||
* @api {get} adminapi/pagans/keyrecovery/:tribe/:email - recovery keys by email
|
||||
* @apiName recoveryKey
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register)
|
||||
@@ -303,7 +304,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
||||
*
|
||||
*/
|
||||
router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
|
||||
const idxreco=`../../nationchains/tribes/${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
|
||||
const idxreco=`../../${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
|
||||
if (fs.existsSync(idxreco)){
|
||||
const emailreco = fs.readJSONSync(idxreco);
|
||||
if (emailreco[req.params.email]){
|
||||
@@ -321,7 +322,7 @@ router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
|
||||
}
|
||||
});
|
||||
/**
|
||||
* @api {get} /pagans/keyrecovery/:tribe/:alias - recovery keys by alias
|
||||
* @api {get} adminapi/pagans/keyrecovery/:tribe/:alias - recovery keys by alias
|
||||
* @apiName recoveryKey
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Send to email recovery if exist key files
|
||||
|
@@ -2,7 +2,7 @@ const express = require("express");
|
||||
const glob = require("glob");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
const conf = require(`../../../../conf/townconf.json`);
|
||||
const Odmdb = require("../models/Odmdb.js");
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
|
@@ -2,7 +2,7 @@ const express = require( 'express' );
|
||||
const fs = require( 'fs-extra' );
|
||||
const path = require( 'path' );
|
||||
const glob = require('glob');
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
const conf = require(`../../../../conf/townconf.json`);
|
||||
|
||||
// Classes
|
||||
const Tribes = require( '../models/Tribes.js' );
|
||||
@@ -11,8 +11,41 @@ const checkHeaders = require( '../middlewares/checkHeaders' );
|
||||
const isAuthenticated = require( '../middlewares/isAuthenticated' );
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} /tribes/www/:tribeId - tribe list
|
||||
* @api {get} adminapi/tribes/conf/:tribe - tribe list
|
||||
* @apiName getconf
|
||||
* @apiDescription Get list of route and model for a town server
|
||||
* @apiGroup Tribes
|
||||
*
|
||||
* @apiSuccess (object) get tribes conf on this server
|
||||
* @apiSuccessExample {json}
|
||||
* HTTP/1.1 200 OK
|
||||
* {status:200,ref:"Tribes",msg:"tribesconf",data:{routes:[],modele:[{model:,tplstrings:[lg,lg]}]}}
|
||||
*/
|
||||
router.get('/config/:tribe', checkHeaders,isAuthenticated,(req,res)=>{
|
||||
/*console.log("passe la")
|
||||
AJOUTER gestion accessright
|
||||
req.session.header.accessrights.data[ req.params.tribe ] &&
|
||||
req.session.header.accessrights.data[ req.params.tribe ].tribeid &&
|
||||
req.session.header.accessrights.data[ req.params.tribe ].tribeid.includes( 'R' )
|
||||
*/
|
||||
if("authorize"=="authorize"){
|
||||
const tribconf=`../../itm/${req.params.tribe}.json`
|
||||
if (!fs.existsSync(tribconf)){
|
||||
res.status(404).json({status:404,ref:"Tribes",msg:"tribedoesnotexist", data:{tribe:req.params.tribe}})
|
||||
}else{
|
||||
res.status(200).json({satatus:200,ref:"Tribes",msg:"tribconf",data:{conf:fs.readJsonSync(tribconf)}})
|
||||
}
|
||||
}else{
|
||||
res.status( 403 )
|
||||
.json( { msg: [ 'forbidenAccess' ], ref: 'Tribes' } )
|
||||
.end();
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @api {get} adminapi/tribes/www/:tribeId - tribe list
|
||||
* @apiName getlisttrib
|
||||
* @apiDescription Get list of www object (space web)
|
||||
* @apiGroup Tribes
|
||||
@@ -23,7 +56,7 @@ const router = express.Router();
|
||||
* HTTP/1.1 200 OK
|
||||
* {status:200,ref:"Tribes",msg:"listwww",data:{listwww}}
|
||||
*/
|
||||
router.get('www', checkHeaders,isAuthenticated,(req,res)=>{
|
||||
router.get('/www', checkHeaders,isAuthenticated,(req,res)=>{
|
||||
let listwww=[]
|
||||
glob.sync(`${conf.dirtown}/tribes/${req.params.tribeId}/www/*`).forEach(d=>{
|
||||
listwww.push(d.split("/").pop())
|
||||
@@ -127,7 +160,7 @@ router.get( '/plugins/:tribeid/:pluginname/:key/:filename', ( req, res ) => {
|
||||
} );
|
||||
|
||||
router.get( '/dirls', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
// url /Tribes/dirls?rep=referentials/dataManagement
|
||||
// url adminapi/tribes/dirls?rep=referentials/dataManagement
|
||||
// request information about a req.query.rep from header xworkon/
|
||||
// return
|
||||
// {file:[{}],dir:[{}]}
|
||||
@@ -145,7 +178,7 @@ router.get( '/dirls', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
} )
|
||||
router.delete( '/ls', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
// check Accessright with D or O on each
|
||||
// url /Tribes/ls
|
||||
// url adminapi/tribes/ls
|
||||
// req.body.files=[listfiles file to delete ]
|
||||
const authfiles = Tribes.checkaccessfiles( req.body, 'D', req.session.header.accessrights, req.session.header.apixpaganid );
|
||||
authfiles.ok.forEach( f => { fs.remove( `${config.tribes}/${f}` ); } )
|
||||
@@ -202,7 +235,7 @@ router.post( '/downloadls', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
}
|
||||
} );
|
||||
router.post( '/upfilepond', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
console.log( 'post /Tribes/uploadfilepond' );
|
||||
console.log( 'post adminapi/tribes/uploadfilepond' );
|
||||
// Store file and return a unique id to save button
|
||||
// that provide folder where to store it
|
||||
const formidable = require( 'formidable' );
|
||||
@@ -278,7 +311,7 @@ router.post( '/uploadfile', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
router.post( '/uploadzip', checkHeaders, ( req, res ) => {
|
||||
console.log( 'uploadzip a file ' )
|
||||
|
||||
/* no authentification to upload a zip filename into /tribes/${xworkon}/${clientconf.uploadzip[filename].dest}
|
||||
/* no authentification to upload a zip filename into adminapi/tribes/${xworkon}/${clientconf.uploadzip[filename].dest}
|
||||
unzip it using the password ${clientconf.uploadzip[filename].psw
|
||||
if no error then run the callback ${clientconf.uploadzip[filename].callback
|
||||
but a password to unzip
|
||||
@@ -352,7 +385,7 @@ router.post( '/uploadzip', checkHeaders, ( req, res ) => {
|
||||
|
||||
router.post( '/upload', checkHeaders, isAuthenticated, ( req, res ) => {
|
||||
1 // ACHANGER VIA usage sendjson
|
||||
// url /Tribes/upload?save=tmp&rep=referentials/dataManagement
|
||||
// url adminapi/tribes/upload?save=tmp&rep=referentials/dataManagement
|
||||
// if save=tmp then store in a tmp file
|
||||
// if save=ok then mv the tmp file to the folder
|
||||
// midlleware hasAccessrighton.js is not apply here only to access/update/create information inside an object
|
||||
|
Reference in New Issue
Block a user