[task-192] [int]
This commit is contained in:
parent
00f416a126
commit
6ad47e1943
9 changed files with 95 additions and 149 deletions
|
@ -10,13 +10,17 @@ namespace _zeitbild.api
|
||||||
{
|
{
|
||||||
register<
|
register<
|
||||||
null,
|
null,
|
||||||
null | Array<
|
(
|
||||||
{
|
null
|
||||||
id : int;
|
|
|
||||||
name : string;
|
Array<
|
||||||
access_level : string;
|
{
|
||||||
}
|
id : int;
|
||||||
>
|
name : string;
|
||||||
|
access_level : string;
|
||||||
|
}
|
||||||
|
>
|
||||||
|
)
|
||||||
>
|
>
|
||||||
(
|
(
|
||||||
rest_subject,
|
rest_subject,
|
||||||
|
@ -30,23 +34,12 @@ namespace _zeitbild.api
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
}),
|
}),
|
||||||
"query_parameters": () => ([
|
"restriction": restriction_web_auth,
|
||||||
{
|
"execution": async (stuff) => {
|
||||||
"name": "username",
|
const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff);
|
||||||
"required": true,
|
|
||||||
"description": "username",
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
/**
|
|
||||||
* @todo
|
|
||||||
*/
|
|
||||||
"restriction": restriction_none,
|
|
||||||
"execution": async ({"query_parameters": query_parameters}) => {
|
|
||||||
const username : string = query_parameters["username"];
|
|
||||||
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(username);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
_zeitbild.service.calendar.overview(user_id)
|
_zeitbild.service.calendar.overview(user.id)
|
||||||
.then(
|
.then(
|
||||||
(data_raw) => Promise.resolve(
|
(data_raw) => Promise.resolve(
|
||||||
data_raw
|
data_raw
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace _zeitbild.api
|
||||||
{
|
{
|
||||||
register<
|
register<
|
||||||
null,
|
null,
|
||||||
boolean
|
null
|
||||||
>
|
>
|
||||||
(
|
(
|
||||||
rest_subject,
|
rest_subject,
|
||||||
|
@ -21,8 +21,7 @@ namespace _zeitbild.api
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
}),
|
}),
|
||||||
"output_schema": () => ({
|
"output_schema": () => ({
|
||||||
"nullable": false,
|
"nullable": true,
|
||||||
"type": "boolean",
|
|
||||||
}),
|
}),
|
||||||
"query_parameters": () => ([
|
"query_parameters": () => ([
|
||||||
{
|
{
|
||||||
|
@ -36,17 +35,11 @@ namespace _zeitbild.api
|
||||||
"description": "password",
|
"description": "password",
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
"restriction": restriction_none,
|
"restriction": restriction_web_auth,
|
||||||
"execution": async ({"query_parameters": query_parameters}) => {
|
"execution": async (stuff) => {
|
||||||
const username : string = query_parameters["username"];
|
|
||||||
const password : string = query_parameters["password"];
|
|
||||||
/**
|
|
||||||
* @todo [important] rectify
|
|
||||||
*/
|
|
||||||
const valid : boolean = (username === password);
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
"status_code": 200,
|
"status_code": 200,
|
||||||
"data": valid,
|
"data": null,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,13 @@ namespace _zeitbild.api
|
||||||
{
|
{
|
||||||
register<
|
register<
|
||||||
null,
|
null,
|
||||||
lib_plankton.ical.type_vcalendar
|
(null | lib_plankton.ical.type_vcalendar)
|
||||||
>(
|
>(
|
||||||
rest_subject,
|
rest_subject,
|
||||||
lib_plankton.http.enum_method.get,
|
lib_plankton.http.enum_method.get,
|
||||||
"/davina/event_get",
|
"/davina/event_get",
|
||||||
{
|
{
|
||||||
"query_parameters": () => ([
|
"query_parameters": () => ([
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"required": true,
|
|
||||||
"description": "user name",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "calendar_id",
|
"name": "calendar_id",
|
||||||
"required": true,
|
"required": true,
|
||||||
|
@ -51,16 +46,12 @@ namespace _zeitbild.api
|
||||||
// .replace(new RegExp("[\\s\\S]*BEGIN:VEVENT([\\s\\S]*)END:VEVENT[\\s\\S]*", "m"), "BEGIN:VEVENT$1END:VEVENT")
|
// .replace(new RegExp("[\\s\\S]*BEGIN:VEVENT([\\s\\S]*)END:VEVENT[\\s\\S]*", "m"), "BEGIN:VEVENT$1END:VEVENT")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
/**
|
"restriction": restriction_web_auth,
|
||||||
* @todo
|
|
||||||
*/
|
|
||||||
"restriction": restriction_none,
|
|
||||||
"execution": async (stuff) => {
|
"execution": async (stuff) => {
|
||||||
const username : string = stuff.query_parameters["username"];
|
const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff);
|
||||||
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(username);
|
|
||||||
|
|
||||||
const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]);
|
const calendar_id : int = parseInt(stuff.query_parameters["calendar_id"]);
|
||||||
const calendar_object : _zeitbild.type_calendar_object = await _zeitbild.service.calendar.get(calendar_id, user_id);
|
const calendar_object : _zeitbild.type_calendar_object = await _zeitbild.service.calendar.get(calendar_id, user.id);
|
||||||
const event_id : int = parseInt(stuff.query_parameters["event_id"]);
|
const event_id : int = parseInt(stuff.query_parameters["event_id"]);
|
||||||
const event_object : _zeitbild.type_event_object = await _zeitbild.service.resource.event_get(calendar_object.resource_id, event_id);
|
const event_object : _zeitbild.type_event_object = await _zeitbild.service.resource.event_get(calendar_object.resource_id, event_id);
|
||||||
|
|
||||||
|
|
|
@ -25,18 +25,6 @@ namespace _zeitbild.api
|
||||||
lib_plankton.http.enum_method.get,
|
lib_plankton.http.enum_method.get,
|
||||||
"/davina/event_list",
|
"/davina/event_list",
|
||||||
{
|
{
|
||||||
"query_parameters": () => ([
|
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"required": true,
|
|
||||||
"description": "user name",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "calendar_id",
|
|
||||||
"required": true,
|
|
||||||
"description": "calendar ID",
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
"output_schema": () => ({
|
"output_schema": () => ({
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
@ -59,14 +47,10 @@ namespace _zeitbild.api
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
/**
|
"restriction": restriction_web_auth,
|
||||||
* @todo
|
|
||||||
*/
|
|
||||||
"restriction": restriction_none,
|
|
||||||
"execution": async (stuff) => {
|
"execution": async (stuff) => {
|
||||||
const username : string = stuff.query_parameters["username"];
|
const user : {id : _zeitbild.type_user_id; object : _zeitbild.type_user_object;} = await _zeitbild.api.user_from_web_auth(stuff);
|
||||||
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(username);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo
|
* @todo
|
||||||
*/
|
*/
|
||||||
|
@ -79,7 +63,7 @@ namespace _zeitbild.api
|
||||||
[calendar_id],
|
[calendar_id],
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
user_id
|
user.id
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
(data) => Promise.resolve(
|
(data) => Promise.resolve(
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace _zeitbild.api
|
||||||
{
|
{
|
||||||
"name": data.userinfo.name,
|
"name": data.userinfo.name,
|
||||||
"email_address": data.userinfo.email,
|
"email_address": data.userinfo.email,
|
||||||
|
"dav_token": null,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
lib_plankton.log.info(
|
lib_plankton.log.info(
|
||||||
|
|
|
@ -6,10 +6,10 @@ namespace _zeitbild.api
|
||||||
* @todo zu plankton auslagern?
|
* @todo zu plankton auslagern?
|
||||||
*/
|
*/
|
||||||
type type_stuff = {
|
type type_stuff = {
|
||||||
version: (null | string);
|
version : (null | string);
|
||||||
headers: Record<string, string>;
|
headers : Record<string, string>;
|
||||||
path_parameters: Record<string, string>;
|
path_parameters : Record<string, string>;
|
||||||
query_parameters: Record<string, string>;
|
query_parameters : Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,39 +24,49 @@ namespace _zeitbild.api
|
||||||
return {"key": key, "value": value};
|
return {"key": key, "value": value};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo outsource?
|
|
||||||
*/
|
*/
|
||||||
export async function web_auth(
|
export async function user_from_web_auth(
|
||||||
authorization_string : (null | string),
|
stuff : {headers : Record<string, string>;}
|
||||||
|
) : Promise<
|
||||||
{
|
{
|
||||||
"via_dav_token": via_dav_token = false,
|
id : _zeitbild.type_user_id;
|
||||||
} : {
|
object : _zeitbild.type_user_object;
|
||||||
via_dav_token ?: boolean;
|
|
||||||
} = {
|
|
||||||
}
|
}
|
||||||
) : Promise<(null | _zeitbild.type_user_id)>
|
>
|
||||||
{
|
{
|
||||||
if (authorization_string === null) {
|
const authorization_string : string = (
|
||||||
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
|
stuff.headers["Authorization"]
|
||||||
|
??
|
||||||
|
stuff.headers["authorization"]
|
||||||
|
??
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (authorization_string === null)
|
||||||
|
{
|
||||||
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
const parts : Array<string> = authorization_string.split(" ");
|
const parts : Array<string> = authorization_string.split(" ");
|
||||||
const strategy : string = parts[0];
|
const strategy : string = parts[0];
|
||||||
const data_raw : string = parts.slice(1).join(" ");
|
const data_raw : string = parts.slice(1).join(" ");
|
||||||
switch (strategy) {
|
switch (strategy)
|
||||||
default: {
|
{
|
||||||
|
default:
|
||||||
|
{
|
||||||
lib_plankton.log.notice(
|
lib_plankton.log.notice(
|
||||||
"zeitbild.web_auth.unhandled_strategy",
|
"zeitbild.user_from_web_auth.unhandled_strategy",
|
||||||
{
|
{
|
||||||
"strategy": strategy,
|
"strategy": strategy,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
|
return Promise.reject();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "Basic": {
|
case "Basic":
|
||||||
|
{
|
||||||
const data_raw_decoded : string = lib_plankton.base64.decode(data_raw);
|
const data_raw_decoded : string = lib_plankton.base64.decode(data_raw);
|
||||||
const parts_ : Array<string> = data_raw_decoded.split(":");
|
const parts_ : Array<string> = data_raw_decoded.split(":");
|
||||||
const username : string = parts_[0];
|
const username : string = parts_[0];
|
||||||
|
@ -64,28 +74,34 @@ namespace _zeitbild.api
|
||||||
const {"value": user_id, "error": error} = await lib_plankton.call.try_catch_wrap_async<_zeitbild.type_user_id>(
|
const {"value": user_id, "error": error} = await lib_plankton.call.try_catch_wrap_async<_zeitbild.type_user_id>(
|
||||||
() => _zeitbild.service.user.identify(username)
|
() => _zeitbild.service.user.identify(username)
|
||||||
);
|
);
|
||||||
if (error !== null) {
|
if ((error !== null) || (user_id === null))
|
||||||
|
{
|
||||||
lib_plankton.log.notice(
|
lib_plankton.log.notice(
|
||||||
"zeitbild.web_auth.unknown_user",
|
"zeitbild.user_from_web_auth.unknown_user",
|
||||||
{
|
{
|
||||||
"username": username,
|
"username": username,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
const user_object : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
const user_object : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
||||||
const password_shall : string = (
|
const password_shall : string = (
|
||||||
via_dav_token
|
(user_object.dav_token !== null)
|
||||||
?
|
?
|
||||||
user_object.dav_token
|
user_object.dav_token
|
||||||
:
|
:
|
||||||
|
/**
|
||||||
|
* @todo deprecate?
|
||||||
|
*/
|
||||||
lib_plankton.sha256.get(
|
lib_plankton.sha256.get(
|
||||||
username,
|
username,
|
||||||
_zeitbild.conf.get()["misc"]["auth_salt"]
|
_zeitbild.conf.get()["misc"]["auth_salt"]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (! (password_is === password_shall)) {
|
if (! (password_is === password_shall))
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @todo remove
|
* @todo remove
|
||||||
*/
|
*/
|
||||||
|
@ -96,10 +112,11 @@ namespace _zeitbild.api
|
||||||
"is": password_is,
|
"is": password_is,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
return Promise.resolve<(null | _zeitbild.type_user_id)>(user_id);
|
{
|
||||||
|
return Promise.resolve({"id": user_id, "object": user_object});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -118,9 +135,9 @@ namespace _zeitbild.api
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
export const restriction_logged_in : lib_plankton.rest_caldav.type_restriction<any> = (
|
export const restriction_web_auth : lib_plankton.rest_caldav.type_restriction<any> = (
|
||||||
(stuff) => (
|
stuff => (
|
||||||
session_from_stuff(stuff)
|
user_from_web_auth(stuff)
|
||||||
.then(() => Promise.resolve<boolean>(true))
|
.then(() => Promise.resolve<boolean>(true))
|
||||||
.catch(() => Promise.resolve<boolean>(false))
|
.catch(() => Promise.resolve<boolean>(false))
|
||||||
)
|
)
|
||||||
|
@ -129,50 +146,11 @@ namespace _zeitbild.api
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
export const restriction_basic_auth : lib_plankton.rest_caldav.type_restriction<any> = (
|
export const restriction_logged_in : lib_plankton.rest_caldav.type_restriction<any> = (
|
||||||
(stuff) => (
|
(stuff) => (
|
||||||
web_auth(
|
session_from_stuff(stuff)
|
||||||
(
|
.then(() => Promise.resolve<boolean>(true))
|
||||||
stuff.headers["Authorization"]
|
.catch(() => Promise.resolve<boolean>(false))
|
||||||
??
|
|
||||||
stuff.headers["authorization"]
|
|
||||||
??
|
|
||||||
null
|
|
||||||
),
|
|
||||||
{
|
|
||||||
"via_dav_token": false,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then<boolean>(
|
|
||||||
(user_id) => Promise.resolve<boolean>(
|
|
||||||
(user_id !== null)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export const restriction_dav_token : lib_plankton.rest_caldav.type_restriction<any> = (
|
|
||||||
(stuff) => (
|
|
||||||
web_auth(
|
|
||||||
(
|
|
||||||
stuff.headers["Authorization"]
|
|
||||||
??
|
|
||||||
stuff.headers["authorization"]
|
|
||||||
??
|
|
||||||
null
|
|
||||||
),
|
|
||||||
{
|
|
||||||
"via_dav_token": true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then<boolean>(
|
|
||||||
(user_id) => Promise.resolve<boolean>(
|
|
||||||
(user_id !== null)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace _zeitbild.api
|
||||||
_zeitbild.api.register_export_ical(rest_subject);
|
_zeitbild.api.register_export_ical(rest_subject);
|
||||||
}
|
}
|
||||||
// caldav
|
// caldav
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_caldav_sniff(rest_subject);
|
_zeitbild.api.register_caldav_sniff(rest_subject);
|
||||||
_zeitbild.api.register_caldav_put(rest_subject);
|
_zeitbild.api.register_caldav_put(rest_subject);
|
||||||
|
@ -59,6 +60,7 @@ namespace _zeitbild.api
|
||||||
_zeitbild.api.register_caldav_projects(rest_subject);
|
_zeitbild.api.register_caldav_projects(rest_subject);
|
||||||
_zeitbild.api.register_caldav_get(rest_subject);
|
_zeitbild.api.register_caldav_get(rest_subject);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// davina
|
// davina
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_davina_check(rest_subject);
|
_zeitbild.api.register_davina_check(rest_subject);
|
||||||
|
|
|
@ -28,6 +28,16 @@ namespace _zeitbild.service.user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function get(
|
||||||
|
user_id : _zeitbild.type_user_id
|
||||||
|
) : Promise<_zeitbild.type_user_object>
|
||||||
|
{
|
||||||
|
return _zeitbild.repository.user.read(user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
export function add(
|
export function add(
|
||||||
|
|
|
@ -77,12 +77,6 @@ ${dir_temp}/zeitbild-unlinked.js: \
|
||||||
${dir_source}/api/actions/calendar_event_remove.ts \
|
${dir_source}/api/actions/calendar_event_remove.ts \
|
||||||
${dir_source}/api/actions/events.ts \
|
${dir_source}/api/actions/events.ts \
|
||||||
${dir_source}/api/actions/export_ical.ts \
|
${dir_source}/api/actions/export_ical.ts \
|
||||||
${dir_source}/api/actions/caldav_sniff.ts \
|
|
||||||
${dir_source}/api/actions/caldav_put.ts \
|
|
||||||
${dir_source}/api/actions/caldav_probe.ts \
|
|
||||||
${dir_source}/api/actions/caldav_probe_via_well_known.ts \
|
|
||||||
${dir_source}/api/actions/caldav_projects.ts \
|
|
||||||
${dir_source}/api/actions/caldav_get.ts \
|
|
||||||
${dir_source}/api/actions/davina_check.ts \
|
${dir_source}/api/actions/davina_check.ts \
|
||||||
${dir_source}/api/actions/davina_calendars.ts \
|
${dir_source}/api/actions/davina_calendars.ts \
|
||||||
${dir_source}/api/actions/davina_event_list.ts \
|
${dir_source}/api/actions/davina_event_list.ts \
|
||||||
|
|
Loading…
Add table
Reference in a new issue