Gruppen-Steuerung #2

Merged
fenris merged 6 commits from task-416 into main 2025-10-23 19:16:29 +02:00
4 changed files with 127 additions and 75 deletions
Showing only changes of commit 2eed983131 - Show all commits

View file

@ -123,67 +123,87 @@ namespace _zeitbild.api
} }
else else
{ {
try // groups
{ const group_ids : Array<_zeitbild.type_group_id> = await Promise.all<_zeitbild.type_group_id>(
// groups (data.userinfo.groups ?? [])
const group_ids : Array<_zeitbild.type_group_id> = await Promise.all<_zeitbild.type_group_id>( .map(
(data.userinfo.groups ?? []) async (group_name_raw) => {
.map( const group_name : string = get_group_name(group_name_raw);
async (group_name_raw) => { const group_id_raw : (null | _zeitbild.type_group_id) = await (
const group_name : string = get_group_name(group_name_raw); _zeitbild.repository.group.identify(group_name)
let group_id : (null | _zeitbild.type_group_id) = await (() => { .catch(() => Promise.resolve(null))
try );
if (group_id_raw === null)
{
const group_id : _zeitbild.type_group_id = await _zeitbild.service.group.add(
{ {
return _zeitbild.repository.group.identify(group_name); "name": group_name,
"label": get_group_label(group_name_raw),
} }
catch (error) );
{ return group_id;
return Promise.resolve(null); }
} else
}) (); {
if (group_id === null) const group_id : _zeitbild.type_group_id = group_id_raw;
{ await _zeitbild.service.group.change(
group_id = await _zeitbild.service.group.add( group_id,
{ {
"name": group_name, "name": group_name,
"label": get_group_label(group_name_raw), "label": get_group_label(group_name_raw),
} }
); );
return group_id; return group_id;
}
else
{
await _zeitbild.service.group.change(
group_id,
{
"name": group_name,
"label": get_group_label(group_name_raw),
}
);
return group_id;
}
} }
)
);
await _zeitbild.service.user.add(
{
"name": data.userinfo.name,
"groups": group_ids,
"email_address": data.userinfo.email,
"dav_token": null,
} }
)
);
const user_id : _zeitbild.type_user_id = await (async () => {
const user_object : _zeitbild.type_user_object = {
"name": (data.userinfo.name as string),
"groups": group_ids,
"email_address": data.userinfo.email,
"dav_token": null,
};
const user_id_raw : (null | _zeitbild.type_user_id) = await (
_zeitbild.service.user.identify(data.userinfo.name as string)
.catch(() => Promise.resolve(null))
); );
lib_plankton.log.info( if (user_id_raw === null)
"user_provisioned", {
{ // provision
"name": data.userinfo.name, const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.add(
} user_object
); );
} lib_plankton.log.info(
catch (error) "user_provisioned",
{ {
// do nothing "id": user_id,
} "name": user_object.name,
}
);
return user_id;
}
else
{
const user_id : _zeitbild.type_user_id = user_id_raw;
// update
await _zeitbild.service.user.change(
user_id,
user_object
);
lib_plankton.log.info(
"user_updated",
{
"id": user_id,
"name": user_object.name,
}
);
return user_id;
}
}) ();
const session_key : string = await lib_plankton.session.begin( const session_key : string = await lib_plankton.session.begin(
data.userinfo.name, data.userinfo.name,
{ {

View file

@ -100,6 +100,7 @@ namespace _zeitbild.auth
"openid", "openid",
"profile", "profile",
"email", "email",
"groups",
], ],
"label": _zeitbild.conf.get().authentication.data.label, "label": _zeitbild.conf.get().authentication.data.label,
} }

View file

@ -639,31 +639,62 @@ namespace _zeitbild.repository.calendar
(x : Array<Record<string, any>>) => x.map( (x : Array<Record<string, any>>) => x.map(
(row : Record<string, any>) => ({ (row : Record<string, any>) => ({
"id": row["id"], "id": row["id"],
"name": row["name"], "name": lib_plankton.call.convey(
"hue": (row["hue"] / hue_scaling), row["name"],
[
// JSON.parse,
(x : Array<string>) => x[0],
]
),
"hue": lib_plankton.call.convey(
row["hue"],
[
// JSON.parse,
(x : Array<int>) => x[0],
(x : int) => (x / hue_scaling),
]
),
/** /**
* @todo use _zeitbild.access_level_determine * @todo use _zeitbild.access_level_determine
*/ */
"access_level": _zeitbild.access_level_determine_raw( "access_level": _zeitbild.access_level_determine_raw(
row["access_public"], lib_plankton.call.convey(
row["access_public"],
[
// JSON.parse,
(x : Array<boolean>) => x[0],
]
),
( (
(user_id === null) (user_id === null)
? ?
null null
: :
{ {
"default": decode_access_level(row["access_level_default"]), "default": lib_plankton.call.convey(
"group": ( row["access_level_default"],
lib_plankton.call.null_prop<string, Array<_zeitbild.enum_access_level>>( [
row["access_level_attributed_group"], // JSON.parse,
x => x.split(",").map(parseInt).map(decode_access_level) (x : Array<int>) => x[0],
) decode_access_level,
?? ]
[]
), ),
"user": lib_plankton.call.null_prop<int, _zeitbild.enum_access_level>( "group": lib_plankton.call.convey(
row["access_level_attributed_group"],
[
// JSON.parse,
(x : Array<(null | int)>) => x.filter(y => (y !== null)),
(x : Array<int>) => x.map(decode_access_level),
]
),
"user": lib_plankton.call.convey(
row["access_level_attributed_user"], row["access_level_attributed_user"],
decode_access_level [
// JSON.parse,
(x : Array<(null | int)>) => x.filter(y => (y !== null)),
(x : Array<int>) => x.map(decode_access_level),
(x : Array<_zeitbild.enum_access_level>) => ((x.length > 0) ? x[0] : null),
]
), ),
} }
) )

View file

@ -1,11 +1,11 @@
SELECT SELECT
x.id AS id, x.id AS id,
MAX(x.name) AS name, JSON_AGG(x.name) AS name,
MAX(x.hue) AS hue, JSON_AGG(x.hue) AS hue,
MAX(x.access_public) AS access_public, JSON_AGG(x.access_public) AS access_public,
MAX(x.access_level_default) AS access_level_default, JSON_AGG(x.access_level_default) AS access_level_default,
GROUP_CONCAT(y1.level, ',') AS access_level_attributed_group, JSON_AGG(y1.level) AS access_level_attributed_group,
GROUP_CONCAT(y2.level, ',') AS access_level_attributed_user JSON_AGG(y2.level) AS access_level_attributed_user
FROM FROM
calendars AS x calendars AS x
LEFT OUTER JOIN calendar_access_attributed_group AS y1 ON ((x.id = y1.calendar_id) AND (y1.group_id IN (SELECT group_id FROM user_groups WHERE (user_id = $user_id)))) LEFT OUTER JOIN calendar_access_attributed_group AS y1 ON ((x.id = y1.calendar_id) AND (y1.group_id IN (SELECT group_id FROM user_groups WHERE (user_id = $user_id))))