[add] api:user_dav_conf [add] api:user_dav_token [mod] conf:add caldav node
This commit is contained in:
parent
a716cf6852
commit
74f79ae0b7
152
source/api/actions/user_dav_conf.ts
Normal file
152
source/api/actions/user_dav_conf.ts
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
namespace _zeitbild.api
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function register_user_dav_conf(
|
||||||
|
rest_subject : lib_plankton.rest_http.type_rest
|
||||||
|
) : void
|
||||||
|
{
|
||||||
|
register<
|
||||||
|
null,
|
||||||
|
(
|
||||||
|
null
|
||||||
|
|
|
||||||
|
{
|
||||||
|
address : string;
|
||||||
|
username : string;
|
||||||
|
password : (null | string);
|
||||||
|
setup_hints : Array<
|
||||||
|
{
|
||||||
|
label : string;
|
||||||
|
link : string;
|
||||||
|
remark : (null | string);
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
>(
|
||||||
|
rest_subject,
|
||||||
|
lib_plankton.http.enum_method.get,
|
||||||
|
"/user_dav_conf",
|
||||||
|
{
|
||||||
|
"description": "gibt die CalDAV-Zugangsdaten eines Nutzers aus",
|
||||||
|
"output_schema": () => ({
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"setup_hints": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"link": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"remark": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string",
|
||||||
|
"default": null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"label",
|
||||||
|
"link",
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"default": []
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"address",
|
||||||
|
"username",
|
||||||
|
"password",
|
||||||
|
"setup_hints",
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
}),
|
||||||
|
"restriction": restriction_logged_in,
|
||||||
|
"execution": async (stuff) => {
|
||||||
|
let result : (
|
||||||
|
null
|
||||||
|
|
|
||||||
|
{
|
||||||
|
address : string;
|
||||||
|
username : string;
|
||||||
|
password : (null | string);
|
||||||
|
setup_hints : Array<
|
||||||
|
{
|
||||||
|
label : string;
|
||||||
|
link : string;
|
||||||
|
remark : (null | string);
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
) = null;
|
||||||
|
const raw : (null | any) = _zeitbild.conf.get()["caldav"];
|
||||||
|
if (raw === null)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const session : {key : string; value : lib_plankton.session.type_session;} = await session_from_stuff(stuff);
|
||||||
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(session.value.name);
|
||||||
|
const user_object : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
||||||
|
const arguments_ : Record<string, string> = Object.fromEntries(
|
||||||
|
[
|
||||||
|
{"key": "username", "value": user_object.name},
|
||||||
|
{"key": "password", "value": user_object.dav_token},
|
||||||
|
]
|
||||||
|
.filter(
|
||||||
|
entry => (entry.value !== null)
|
||||||
|
)
|
||||||
|
.map(
|
||||||
|
entry => ([entry.key, entry.value as string])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
result = {
|
||||||
|
"address": lib_plankton.string.coin(raw["address"], arguments_),
|
||||||
|
"username": lib_plankton.string.coin(raw["username"], arguments_),
|
||||||
|
"password": (
|
||||||
|
(user_object.dav_token === null)
|
||||||
|
?
|
||||||
|
null
|
||||||
|
:
|
||||||
|
lib_plankton.string.coin(raw["password"], arguments_)
|
||||||
|
),
|
||||||
|
"setup_hints": raw["setup_hints"],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return Promise.resolve(
|
||||||
|
{
|
||||||
|
"status_code": 200,
|
||||||
|
"data": result,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
53
source/api/actions/user_dav_token.ts
Normal file
53
source/api/actions/user_dav_token.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
namespace _zeitbild.api
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function register_user_dav_token(
|
||||||
|
rest_subject : lib_plankton.rest_http.type_rest
|
||||||
|
) : void
|
||||||
|
{
|
||||||
|
register<
|
||||||
|
// string,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
>(
|
||||||
|
rest_subject,
|
||||||
|
lib_plankton.http.enum_method.patch,
|
||||||
|
"/user_dav_token",
|
||||||
|
{
|
||||||
|
"description": "setzt/überschreibt den DAV-Token eines Nutzers",
|
||||||
|
/*
|
||||||
|
"input_schema": () => ({
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
}),
|
||||||
|
*/
|
||||||
|
"input_schema": () => ({
|
||||||
|
"nullable": true,
|
||||||
|
}),
|
||||||
|
"output_schema": () => ({
|
||||||
|
"nullable": true
|
||||||
|
}),
|
||||||
|
"restriction": restriction_logged_in,
|
||||||
|
"execution": async (stuff) => {
|
||||||
|
const session : {key : string; value : lib_plankton.session.type_session;} = await session_from_stuff(stuff);
|
||||||
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(session.value.name);
|
||||||
|
// TODO: outsource to user service?
|
||||||
|
const user_object : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
||||||
|
// user_object.dav_token = stuff.input;
|
||||||
|
user_object.dav_token = lib_plankton.random.generate_string({"length": 12});
|
||||||
|
await _zeitbild.service.user.change(user_id, user_object);
|
||||||
|
return Promise.resolve(
|
||||||
|
{
|
||||||
|
"status_code": 200,
|
||||||
|
"data": null,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -31,6 +31,15 @@ namespace _zeitbild.api
|
||||||
_zeitbild.api.register_session_end(rest_subject);
|
_zeitbild.api.register_session_end(rest_subject);
|
||||||
_zeitbild.api.register_session_oidc(rest_subject);
|
_zeitbild.api.register_session_oidc(rest_subject);
|
||||||
}
|
}
|
||||||
|
// user
|
||||||
|
{
|
||||||
|
_zeitbild.api.register_users(rest_subject);
|
||||||
|
// caldav
|
||||||
|
{
|
||||||
|
_zeitbild.api.register_user_dav_conf(rest_subject);
|
||||||
|
_zeitbild.api.register_user_dav_token(rest_subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
// calendar
|
// calendar
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_calendar_list(rest_subject);
|
_zeitbild.api.register_calendar_list(rest_subject);
|
||||||
|
|
@ -52,7 +61,6 @@ namespace _zeitbild.api
|
||||||
}
|
}
|
||||||
// misc
|
// misc
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_users(rest_subject);
|
|
||||||
_zeitbild.api.register_events(rest_subject);
|
_zeitbild.api.register_events(rest_subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,60 @@ namespace _zeitbild.conf
|
||||||
"default": {
|
"default": {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"caldav": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"address": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"setup_hints": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"link": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"remark": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string",
|
||||||
|
"default": null
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"label",
|
||||||
|
"link",
|
||||||
|
],
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"default": []
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"address",
|
||||||
|
"username",
|
||||||
|
"password"
|
||||||
|
],
|
||||||
|
"additionalProperties": false,
|
||||||
|
"default": null
|
||||||
|
},
|
||||||
"misc": {
|
"misc": {
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,19 @@ namespace _zeitbild.repository.user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export async function update(
|
||||||
|
user_id : _zeitbild.type_user_id,
|
||||||
|
user_object : _zeitbild.type_user_object
|
||||||
|
) : Promise<void>
|
||||||
|
{
|
||||||
|
const dispersal : Record<string, any> = encode(user_object);
|
||||||
|
await get_store().update(user_id, dispersal);
|
||||||
|
return Promise.resolve<void>(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
export async function identify(
|
export async function identify(
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,15 @@ namespace _zeitbild.service.user
|
||||||
return _zeitbild.repository.user.create(user_object);
|
return _zeitbild.repository.user.create(user_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function change(
|
||||||
|
user_id : _zeitbild.type_user_id,
|
||||||
|
user_object : _zeitbild.type_user_object
|
||||||
|
) : Promise<void>
|
||||||
|
{
|
||||||
|
return _zeitbild.repository.user.update(user_id, user_object);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ ${dir_temp}/zeitbild-unlinked.js: \
|
||||||
${dir_source}/api/actions/session_oidc.ts \
|
${dir_source}/api/actions/session_oidc.ts \
|
||||||
${dir_source}/api/actions/session_end.ts \
|
${dir_source}/api/actions/session_end.ts \
|
||||||
${dir_source}/api/actions/users.ts \
|
${dir_source}/api/actions/users.ts \
|
||||||
|
${dir_source}/api/actions/user_dav_conf.ts \
|
||||||
|
${dir_source}/api/actions/user_dav_token.ts \
|
||||||
${dir_source}/api/actions/calendar_list.ts \
|
${dir_source}/api/actions/calendar_list.ts \
|
||||||
${dir_source}/api/actions/calendar_get.ts \
|
${dir_source}/api/actions/calendar_get.ts \
|
||||||
${dir_source}/api/actions/calendar_add.ts \
|
${dir_source}/api/actions/calendar_add.ts \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue