mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Improve interface to makeToken.
It now takes a template that allows setting all options.
This commit is contained in:
parent
3228147eed
commit
cfb5d936ee
1 changed files with 25 additions and 14 deletions
|
@ -2122,7 +2122,7 @@ function userMenu(elt) {
|
||||||
if(serverConnection.version !== "1" &&
|
if(serverConnection.version !== "1" &&
|
||||||
serverConnection.permissions.indexOf('token') >= 0) {
|
serverConnection.permissions.indexOf('token') >= 0) {
|
||||||
items.push({label: 'Invite user', onClick: () => {
|
items.push({label: 'Invite user', onClick: () => {
|
||||||
makeToken(null);
|
makeToken();
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
if(serverConnection.permissions.indexOf('present') >= 0 && canFile())
|
if(serverConnection.permissions.indexOf('present') >= 0 && canFile())
|
||||||
|
@ -3047,11 +3047,11 @@ const units = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} s
|
* @param {string} s
|
||||||
* @returns {string|number}
|
* @returns {Date|number}
|
||||||
*/
|
*/
|
||||||
function parseExpiration(s) {
|
function parseExpiration(s) {
|
||||||
if(!s)
|
if(!s)
|
||||||
return units.d;
|
return null;
|
||||||
let re = /^([0-9]+)(s|min|h|d|yr)$/
|
let re = /^([0-9]+)(s|min|h|d|yr)$/
|
||||||
let e = re.exec(s)
|
let e = re.exec(s)
|
||||||
if(e) {
|
if(e) {
|
||||||
|
@ -3063,7 +3063,7 @@ function parseExpiration(s) {
|
||||||
let d = new Date(s);
|
let d = new Date(s);
|
||||||
if(d.toString() === 'Invalid Date')
|
if(d.toString() === 'Invalid Date')
|
||||||
throw new Error("Couldn't parse expiration date");
|
throw new Error("Couldn't parse expiration date");
|
||||||
return d.toISOString();
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
function protocol2Predicate() {
|
function protocol2Predicate() {
|
||||||
|
@ -3086,20 +3086,25 @@ function editTokenPredicate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} username
|
* @param {Object} [template]
|
||||||
* @param {number|string} [expires]
|
|
||||||
*/
|
*/
|
||||||
function makeToken(username, expires) {
|
function makeToken(template) {
|
||||||
|
if(!template)
|
||||||
|
template = {};
|
||||||
let v = {
|
let v = {
|
||||||
group: group,
|
group: group,
|
||||||
};
|
}
|
||||||
if(username)
|
if('username' in template)
|
||||||
v.username = username;
|
v.username = template.username;
|
||||||
if(expires)
|
if('expires' in template)
|
||||||
v.expires = expires;
|
v.expires = template.expires;
|
||||||
else
|
else
|
||||||
v.expires = units.d;
|
v.expires = units.d;
|
||||||
if(serverConnection.permissions.indexOf('present') >= 0)
|
if('not-before' in template)
|
||||||
|
v["not-before"] = template["not-before"];
|
||||||
|
if('permissions' in template)
|
||||||
|
v.permissions = template.permissions;
|
||||||
|
else if(serverConnection.permissions.indexOf('present') >= 0)
|
||||||
v.permissions = ['present'];
|
v.permissions = ['present'];
|
||||||
else
|
else
|
||||||
v.permissions = [];
|
v.permissions = [];
|
||||||
|
@ -3112,7 +3117,13 @@ commands.invite = {
|
||||||
parameters: "[username] [expiration]",
|
parameters: "[username] [expiration]",
|
||||||
f: (c, r) => {
|
f: (c, r) => {
|
||||||
let p = parseCommand(r);
|
let p = parseCommand(r);
|
||||||
makeToken(p[0], parseExpiration(p[1]));
|
let template = {};
|
||||||
|
if(p[0])
|
||||||
|
template.username = p[0];
|
||||||
|
let expires = parseExpiration(p[1]);
|
||||||
|
if(expires)
|
||||||
|
template.expires = expires;
|
||||||
|
makeToken(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue