Compare commits
2 commits
4733260de1
...
baae6d0c52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baae6d0c52 | ||
|
|
97381a9e1b |
130
source/api/actions/user_get.ts
Normal file
130
source/api/actions/user_get.ts
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
/*
|
||||||
|
This file is part of »zeitbild«.
|
||||||
|
|
||||||
|
Copyright 2025 'kcf' <fenris@folksprak.org>
|
||||||
|
|
||||||
|
»zeitbild« is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
»zeitbild« is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace _zeitbild.api
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function register_user_get(
|
||||||
|
rest_subject : lib_plankton.rest_http.type_rest
|
||||||
|
) : void
|
||||||
|
{
|
||||||
|
register<
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
name : string;
|
||||||
|
groups : Array<
|
||||||
|
int
|
||||||
|
>;
|
||||||
|
email_address : (
|
||||||
|
null
|
||||||
|
|
|
||||||
|
string
|
||||||
|
);
|
||||||
|
dav_token : (
|
||||||
|
null
|
||||||
|
|
|
||||||
|
string
|
||||||
|
);
|
||||||
|
settings : {
|
||||||
|
use_fallback_for_date_and_time_inputs : boolean;
|
||||||
|
weekview_vertical_default : boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
>(
|
||||||
|
rest_subject,
|
||||||
|
lib_plankton.http.enum_method.get,
|
||||||
|
"/user",
|
||||||
|
{
|
||||||
|
"description": "gibt die Angaben eines Nutzers aus",
|
||||||
|
"output_schema": () => ({
|
||||||
|
"nullable": false,
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "number",
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"groups": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "int",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"email_address": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"dav_token": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"use_fallback_for_date_and_time_inputs": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "boolean",
|
||||||
|
},
|
||||||
|
"weekview_vertical_default": {
|
||||||
|
"nullable": false,
|
||||||
|
"type": "boolean",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"use_fallback_for_date_and_time_inputs",
|
||||||
|
"weekview_vertical_default",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
"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);
|
||||||
|
|
||||||
|
const result : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
||||||
|
return Promise.resolve(
|
||||||
|
{
|
||||||
|
"status_code": 200,
|
||||||
|
"data": result,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -58,6 +58,7 @@ namespace _zeitbild.api
|
||||||
// user
|
// user
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_users(rest_subject);
|
_zeitbild.api.register_users(rest_subject);
|
||||||
|
_zeitbild.api.register_user_get(rest_subject);
|
||||||
// caldav
|
// caldav
|
||||||
{
|
{
|
||||||
_zeitbild.api.register_user_dav_conf(rest_subject);
|
_zeitbild.api.register_user_dav_conf(rest_subject);
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,10 @@ namespace _zeitbild.auth
|
||||||
"groups": group_ids,
|
"groups": group_ids,
|
||||||
"email_address": userinfo.email,
|
"email_address": userinfo.email,
|
||||||
"dav_token": null,
|
"dav_token": null,
|
||||||
|
"settings": {
|
||||||
|
"use_fallback_for_date_and_time_inputs": false,
|
||||||
|
"weekview_vertical_default": false,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.add(
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.add(
|
||||||
user_object
|
user_object
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace _zeitbild.database
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
const _compatible_revisions : Array<string> = [
|
const _compatible_revisions : Array<string> = [
|
||||||
"r6",
|
"r7",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,23 @@ namespace _zeitbild.repository.user
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_settings_row_slim = {
|
||||||
|
use_fallback_for_date_and_time_inputs : int;
|
||||||
|
weekview_vertical_default : int;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
type type_settings_row_fat = {
|
||||||
|
user_id : int;
|
||||||
|
use_fallback_for_date_and_time_inputs : int;
|
||||||
|
weekview_vertical_default : int;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
type type_preview = {
|
type type_preview = {
|
||||||
|
|
@ -57,6 +74,7 @@ namespace _zeitbild.repository.user
|
||||||
type type_dispersal = {
|
type type_dispersal = {
|
||||||
core : type_core_row;
|
core : type_core_row;
|
||||||
groups : Array<type_group_row_slim>;
|
groups : Array<type_group_row_slim>;
|
||||||
|
settings : type_settings_row_slim;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -90,6 +108,21 @@ namespace _zeitbild.repository.user
|
||||||
) = null;
|
) = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
var _store_settings : (
|
||||||
|
null
|
||||||
|
|
|
||||||
|
lib_plankton.storage.type_store<
|
||||||
|
int,
|
||||||
|
/*type_settings_row_fat*/Record<string, any>,
|
||||||
|
{},
|
||||||
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
||||||
|
Record<string, any>
|
||||||
|
>
|
||||||
|
) = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
function get_store_core(
|
function get_store_core(
|
||||||
|
|
@ -150,6 +183,36 @@ namespace _zeitbild.repository.user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function get_store_settings(
|
||||||
|
)
|
||||||
|
: lib_plankton.storage.type_store<
|
||||||
|
int,
|
||||||
|
/*type_group_row_fat*/Record<string, any>,
|
||||||
|
{},
|
||||||
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
||||||
|
Record<string, any>
|
||||||
|
>
|
||||||
|
{
|
||||||
|
if (_store_settings === null)
|
||||||
|
{
|
||||||
|
_store_settings = lib_plankton.storage.sql_table_autokey_store(
|
||||||
|
{
|
||||||
|
"database_implementation": _zeitbild.database.get_implementation(),
|
||||||
|
"table_name": "user_settings",
|
||||||
|
"key_name": "id",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
return _store_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
function encode(
|
function encode(
|
||||||
|
|
@ -172,6 +235,10 @@ namespace _zeitbild.repository.user
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
"settings": {
|
||||||
|
"use_fallback_for_date_and_time_inputs": (user_object.settings.use_fallback_for_date_and_time_inputs ? 0 : 1),
|
||||||
|
"weekview_vertical_default": (user_object.settings.weekview_vertical_default ? 0 : 1),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,6 +259,10 @@ namespace _zeitbild.repository.user
|
||||||
),
|
),
|
||||||
"email_address": dispersal.core.email_address,
|
"email_address": dispersal.core.email_address,
|
||||||
"dav_token": dispersal.core.dav_token,
|
"dav_token": dispersal.core.dav_token,
|
||||||
|
"settings": {
|
||||||
|
"use_fallback_for_date_and_time_inputs": (dispersal.settings.use_fallback_for_date_and_time_inputs > 0),
|
||||||
|
"weekview_vertical_default": (dispersal.settings.weekview_vertical_default > 0),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,20 +326,50 @@ namespace _zeitbild.repository.user
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const dispersal : type_dispersal = {
|
const settings_rows : Array<type_settings_row_slim> = (
|
||||||
"core": core_row,
|
(
|
||||||
"groups": (
|
await get_store_settings().search(
|
||||||
group_rows.map(
|
{
|
||||||
group_row_fat => (
|
"expression": "(user_id = $user_id)",
|
||||||
{
|
"arguments": {
|
||||||
"group_id": group_row_fat.group_id,
|
"user_id": user_id,
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
};
|
.map(
|
||||||
const user_object : _zeitbild.type_user_object = decode(dispersal);
|
hit => (
|
||||||
return Promise.resolve<_zeitbild.type_user_object>(user_object);
|
{
|
||||||
|
// "user_id": hit.preview.user_id,
|
||||||
|
"use_fallback_for_date_and_time_inputs": hit.preview.use_fallback_for_date_and_time_inputs,
|
||||||
|
"weekview_vertical_default": hit.preview.weekview_vertical_default,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (settings_rows.length !== 1)
|
||||||
|
{
|
||||||
|
return Promise.reject(new Error("no settings bound"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const settings_row : type_settings_row_slim = settings_rows[0];
|
||||||
|
const dispersal : type_dispersal = {
|
||||||
|
"core": core_row,
|
||||||
|
"groups": (
|
||||||
|
group_rows.map(
|
||||||
|
group_row_fat => (
|
||||||
|
{
|
||||||
|
"group_id": group_row_fat.group_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
"settings": settings_row,
|
||||||
|
};
|
||||||
|
const user_object : _zeitbild.type_user_object = decode(dispersal);
|
||||||
|
return Promise.resolve<_zeitbild.type_user_object>(user_object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -295,6 +396,15 @@ namespace _zeitbild.repository.user
|
||||||
await get_store_groups().create(group_row_fat);
|
await get_store_groups().create(group_row_fat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// settings
|
||||||
|
{
|
||||||
|
const settings_row_fat : type_settings_row_fat = {
|
||||||
|
"user_id": user_id,
|
||||||
|
"use_fallback_for_date_and_time_inputs": dispersal.settings.use_fallback_for_date_and_time_inputs,
|
||||||
|
"weekview_vertical_default": dispersal.settings.weekview_vertical_default,
|
||||||
|
};
|
||||||
|
await get_store_settings().create(settings_row_fat);
|
||||||
|
}
|
||||||
return Promise.resolve<_zeitbild.type_user_id>(user_id);
|
return Promise.resolve<_zeitbild.type_user_id>(user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,6 +468,30 @@ namespace _zeitbild.repository.user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// settings
|
||||||
|
{
|
||||||
|
const settings_row_fat : type_settings_row_fat = {
|
||||||
|
"user_id": user_id,
|
||||||
|
"use_fallback_for_date_and_time_inputs": dispersal.settings.use_fallback_for_date_and_time_inputs,
|
||||||
|
"weekview_vertical_default": dispersal.settings.weekview_vertical_default,
|
||||||
|
};
|
||||||
|
const hits : Array<{key : int; preview : Record<string, any>;}> = await get_store_settings().search(
|
||||||
|
{
|
||||||
|
"expression": "(user_id = $user_id)",
|
||||||
|
"arguments": {
|
||||||
|
"user_id": user_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (hits.length >= 1)
|
||||||
|
{
|
||||||
|
await get_store_settings().update(hits[0].key, settings_row_fat);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await get_store_settings().create(settings_row_fat);
|
||||||
|
}
|
||||||
|
}
|
||||||
return Promise.resolve<void>(undefined);
|
return Promise.resolve<void>(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,10 @@ namespace _zeitbild.sample
|
||||||
"groups": (user_raw.groups ?? []),
|
"groups": (user_raw.groups ?? []),
|
||||||
"email_address": user_raw.email_address,
|
"email_address": user_raw.email_address,
|
||||||
"dav_token": (user_raw.dav_token ?? null),
|
"dav_token": (user_raw.dav_token ?? null),
|
||||||
|
"settings": {
|
||||||
|
"use_fallback_for_date_and_time_inputs": false,
|
||||||
|
"weekview_vertical_default": false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.add(
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.add(
|
||||||
user_object
|
user_object
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,10 @@ namespace _zeitbild
|
||||||
|
|
|
|
||||||
string
|
string
|
||||||
);
|
);
|
||||||
|
settings : {
|
||||||
|
use_fallback_for_date_and_time_inputs : boolean;
|
||||||
|
weekview_vertical_default : boolean;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ cmd_tsc := ${dir_tools}/typescript/node_modules/.bin/tsc
|
||||||
## rules
|
## rules
|
||||||
|
|
||||||
.PHONY: default
|
.PHONY: default
|
||||||
default: node_modules ${dir_build}/zeitbild node_modules
|
default: node_modules ${dir_build}/zeitbild
|
||||||
|
|
||||||
.PHONY: node_modules
|
.PHONY: node_modules
|
||||||
node_modules:
|
node_modules:
|
||||||
|
|
@ -62,6 +62,7 @@ ${dir_temp}/zeitbild-unlinked.js: \
|
||||||
${dir_source}/api/actions/session_status.ts \
|
${dir_source}/api/actions/session_status.ts \
|
||||||
${dir_source}/api/actions/group_list.ts \
|
${dir_source}/api/actions/group_list.ts \
|
||||||
${dir_source}/api/actions/users.ts \
|
${dir_source}/api/actions/users.ts \
|
||||||
|
${dir_source}/api/actions/user_get.ts \
|
||||||
${dir_source}/api/actions/user_dav_conf.ts \
|
${dir_source}/api/actions/user_dav_conf.ts \
|
||||||
${dir_source}/api/actions/user_dav_token.ts \
|
${dir_source}/api/actions/user_dav_token.ts \
|
||||||
${dir_source}/api/actions/calendar_list.ts \
|
${dir_source}/api/actions/calendar_list.ts \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue