Disable additional affiliation constraint when used token is not from owner

This commit is contained in:
lowlighter
2021-04-14 18:37:50 +02:00
parent 7f8f3f6e06
commit 8cba3f449a
4 changed files with 23 additions and 4 deletions

View File

@@ -5,6 +5,7 @@
import processes from "child_process"
import util from "util"
import url from "url"
import OctokitRest from "@octokit/rest"
//Templates and plugins
const Templates = {}
@@ -26,6 +27,7 @@
const logger = log ? console.debug : () => null
logger("metrics/setup > setup")
const conf = {
authenticated:null,
templates:{},
queries:{},
settings:{},
@@ -100,7 +102,7 @@
await fs.promises.rmdir(path.join(__templates, ".community"), {recursive:true})
logger(`metrics/setup > loaded community template ${name}`)
}
catch (error) {
catch (error) {
logger(`metrics/setup > failed to load community template ${template}`)
logger(error)
}
@@ -195,10 +197,21 @@
//Load metadata (plugins)
conf.metadata = await metadata({log})
//Store authenticated user
if (conf.settings.token) {
try {
conf.authenticated = (await (new OctokitRest.Octokit({auth:conf.settings.token})).users.getAuthenticated()).data.login
logger(`metrics/setup > setup > authenticated as ${conf.authenticated}`)
}
catch (error) {
logger(`metrics/setup > setup > could not verify authentication : ${error}`)
}
}
//Set no token property
Object.defineProperty(conf.settings, "notoken", {get() {
return conf.settings.token === "NOT_NEEDED"
}})
return conf.settings.token === "NOT_NEEDED"
}})
//Conf
logger("metrics/setup > setup > success")