pangloss-users 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. pangloss_users-0.1.0/LICENCE.txt +21 -0
  2. pangloss_users-0.1.0/PKG-INFO +21 -0
  3. pangloss_users-0.1.0/README.md +6 -0
  4. pangloss_users-0.1.0/pyproject.toml +27 -0
  5. pangloss_users-0.1.0/pyproject.toml.orig +26 -0
  6. pangloss_users-0.1.0/src/pangloss_users/__init__.py +53 -0
  7. pangloss_users-0.1.0/src/pangloss_users/exceptions.py +14 -0
  8. pangloss_users-0.1.0/src/pangloss_users/interface/README.md +8 -0
  9. pangloss_users-0.1.0/src/pangloss_users/interface/package.json +23 -0
  10. pangloss_users-0.1.0/src/pangloss_users/interface/src/api.ts +103 -0
  11. pangloss_users-0.1.0/src/pangloss_users/interface/src/components/UserPage.tsx +85 -0
  12. pangloss_users-0.1.0/src/pangloss_users/interface/src/components/UsersAdminSection.tsx +556 -0
  13. pangloss_users-0.1.0/src/pangloss_users/interface/src/components/UsersPage.tsx +64 -0
  14. pangloss_users-0.1.0/src/pangloss_users/interface/src/feed.ts +29 -0
  15. pangloss_users-0.1.0/src/pangloss_users/interface/src/index.ts +21 -0
  16. pangloss_users-0.1.0/src/pangloss_users/interface/src/state.test.ts +149 -0
  17. pangloss_users-0.1.0/src/pangloss_users/interface/src/state.ts +151 -0
  18. pangloss_users-0.1.0/src/pangloss_users/interface/tsconfig.json +18 -0
  19. pangloss_users-0.1.0/src/pangloss_users/interface/vitest.config.ts +14 -0
  20. pangloss_users-0.1.0/src/pangloss_users/interface_config.py +8 -0
  21. pangloss_users-0.1.0/src/pangloss_users/models.py +126 -0
  22. pangloss_users-0.1.0/src/pangloss_users/passwords.py +46 -0
  23. pangloss_users-0.1.0/src/pangloss_users/py.typed +0 -0
  24. pangloss_users-0.1.0/src/pangloss_users/service.py +342 -0
  25. pangloss_users-0.1.0/src/pangloss_users/translations/ui.jsonc +47 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026, Richard Hadden, Department of Digital Humanities, University of Graz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: pangloss-users
3
+ Version: 0.1.0
4
+ Summary: Users, passwords and personal access tokens for Pangloss
5
+ Author: Richard Hadden
6
+ Author-email: Richard Hadden <richard.hadden@oeaw.ac.at>
7
+ License-Expression: MIT
8
+ License-File: LICENCE.txt
9
+ Requires-Dist: argon2-cffi>=25.1.0
10
+ Requires-Dist: pangloss-core==0.1.0
11
+ Requires-Dist: pydantic[email]>=2.13.4
12
+ Requires-Python: >=3.15
13
+ Project-URL: Repository, https://github.com/richardhadden/pangloss-monorepo
14
+ Description-Content-Type: text/markdown
15
+
16
+ # pangloss-users
17
+
18
+ User models, Argon2id password hashing, personal access tokens and the `service` functions (`create_user`, `authenticate`,
19
+ `change_password`, …); the users themselves are stored by the database module.
20
+
21
+ Guide: [guide/accounts](../../guide/accounts/README.md). Reference: [implementation_docs/users.md](../../implementation_docs/users.md).
@@ -0,0 +1,6 @@
1
+ # pangloss-users
2
+
3
+ User models, Argon2id password hashing, personal access tokens and the `service` functions (`create_user`, `authenticate`,
4
+ `change_password`, …); the users themselves are stored by the database module.
5
+
6
+ Guide: [guide/accounts](../../guide/accounts/README.md). Reference: [implementation_docs/users.md](../../implementation_docs/users.md).
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "pangloss-users"
3
+ version = "0.1.0"
4
+ description = "Users, passwords and personal access tokens for Pangloss"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENCE.txt"]
8
+ requires-python = ">=3.15"
9
+ dependencies = [
10
+ "argon2-cffi>=25.1.0",
11
+ "pangloss-core==0.1.0",
12
+ "pydantic[email]>=2.13.4",
13
+ ]
14
+
15
+ [[project.authors]]
16
+ name = "Richard Hadden"
17
+ email = "richard.hadden@oeaw.ac.at"
18
+
19
+ [project.urls]
20
+ Repository = "https://github.com/richardhadden/pangloss-monorepo"
21
+
22
+ [build-system]
23
+ requires = ["uv_build>=0.11.8,<0.12.0"]
24
+ build-backend = "uv_build"
25
+
26
+ [tool.uv.sources.pangloss-core]
27
+ workspace = true
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "pangloss-users"
3
+ version = "0.1.0"
4
+ description = "Users, passwords and personal access tokens for Pangloss"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENCE.txt"]
8
+ authors = [
9
+ { name = "Richard Hadden", email = "richard.hadden@oeaw.ac.at" }
10
+ ]
11
+ requires-python = ">=3.15"
12
+ dependencies = [
13
+ "argon2-cffi>=25.1.0",
14
+ "pangloss-core==0.1.0",
15
+ "pydantic[email]>=2.13.4",
16
+ ]
17
+
18
+ [project.urls]
19
+ Repository = "https://github.com/richardhadden/pangloss-monorepo"
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.11.8,<0.12.0"]
23
+ build-backend = "uv_build"
24
+
25
+ [tool.uv.sources]
26
+ pangloss-core = { workspace = true }
@@ -0,0 +1,53 @@
1
+ """Users of Pangloss: their models, passwords and the `service` functions (implementation_docs/users.md)"""
2
+
3
+ from contextvars import ContextVar
4
+
5
+ lazy from pangloss_users.exceptions import (
6
+ PanglossInvalidUserError,
7
+ PanglossUserDoesNotExistError,
8
+ PanglossUserError,
9
+ PanglossUserExistsError,
10
+ )
11
+ lazy from pangloss_users.models import (
12
+ AccessTokenInfo,
13
+ ToolchainCreate,
14
+ User,
15
+ UserCreate,
16
+ UserInDB,
17
+ UserItem,
18
+ UserItems,
19
+ UserSummary,
20
+ UserUpdate,
21
+ )
22
+
23
+ __all__ = [
24
+ "AccessTokenInfo",
25
+ "PanglossInvalidUserError",
26
+ "PanglossUserDoesNotExistError",
27
+ "PanglossUserError",
28
+ "PanglossUserExistsError",
29
+ "ToolchainCreate",
30
+ "User",
31
+ "UserCreate",
32
+ "UserInDB",
33
+ "UserItem",
34
+ "UserItems",
35
+ "UserSummary",
36
+ "UserUpdate",
37
+ "current_request_is_admin",
38
+ "current_request_username",
39
+ "see_unpublished",
40
+ ]
41
+
42
+ current_request_username = ContextVar(
43
+ "current_request_username", default="pangloss_default_user"
44
+ )
45
+
46
+ # Whether the user of the request is an admin. True outside a request (scripts, commands, tests), as they may do
47
+ # anything; the API sets it for the user it finds.
48
+ current_request_is_admin = ContextVar("current_request_is_admin", default=True)
49
+
50
+ # Whether the request may see documents that are not published (`published: false` on the head node;
51
+ # see implementation_docs/review.md). True outside a request (scripts, commands, tests); the API sets it false for
52
+ # a request that is not logged in.
53
+ see_unpublished = ContextVar("see_unpublished", default=True)
@@ -0,0 +1,14 @@
1
+ class PanglossUserError(Exception):
2
+ """Base class for errors about users"""
3
+
4
+
5
+ class PanglossUserExistsError(PanglossUserError):
6
+ """The username or email is already taken"""
7
+
8
+
9
+ class PanglossUserDoesNotExistError(PanglossUserError):
10
+ """There is no such user"""
11
+
12
+
13
+ class PanglossInvalidUserError(PanglossUserError):
14
+ """The details given for a user are not acceptable (e.g. a short password)"""
@@ -0,0 +1,8 @@
1
+ # Interface module of `pangloss_users`
2
+
3
+ A Solid 2.0 library that the interface includes when `pangloss_users` is in `INSTALLED_APPS`. For someone logged in:
4
+
5
+ - `/users` (`UsersPage`, linked from the navigation bar): everyone, by username and full name.
6
+ - `/users/:username` (`UserPage`): the entities and top-level documents the user has made or changed, the most recent
7
+ first, a page at a time.
8
+ - `userHref` in the manifest: the console's "created" and "modified" names link to that page.
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@pangloss-module/pangloss_users",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "The interface module of pangloss_users",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "scripts": {
14
+ "typecheck": "tsc --noEmit -p tsconfig.json",
15
+ "test": "vitest run"
16
+ },
17
+ "peerDependencies": {
18
+ "@pangloss/interface-core": "*",
19
+ "@solidjs/router": "^2.0.0",
20
+ "@solidjs/web": "^2.0.1",
21
+ "solid-js": "^2.0.1"
22
+ }
23
+ }
@@ -0,0 +1,103 @@
1
+ import type { ApiClient } from "@pangloss/interface-core";
2
+
3
+ // What `/api/users` sends for these pages (packages/pangloss-users/src/pangloss_users/models.py)
4
+
5
+ export interface UserSummary {
6
+ username: string;
7
+ fullName?: string | null;
8
+ /** `toolchain`: a program named as a creator of the data it made; it cannot log in */
9
+ kind?: "user" | "toolchain";
10
+ }
11
+
12
+ export interface UserItem {
13
+ id: string;
14
+ type: string;
15
+ label?: string | null;
16
+ action: "created" | "modified";
17
+ /** ISO time */
18
+ when?: string | null;
19
+ }
20
+
21
+ export interface UserItems {
22
+ user: UserSummary;
23
+ results: UserItem[];
24
+ count: number;
25
+ page: number;
26
+ pageSize: number;
27
+ }
28
+
29
+ /** A user as an admin sees them */
30
+ export interface User extends UserSummary {
31
+ email?: string | null;
32
+ admin: boolean;
33
+ disabled: boolean;
34
+ /** ISO time */
35
+ createdWhen?: string | null;
36
+ }
37
+
38
+ export interface NewUser {
39
+ username: string;
40
+ email: string;
41
+ password: string;
42
+ fullName: string | null;
43
+ admin: boolean;
44
+ }
45
+
46
+ export interface AccessToken {
47
+ id: string;
48
+ name: string;
49
+ scope: "read" | "write";
50
+ createdWhen: string;
51
+ expiresWhen?: string | null;
52
+ lastUsedWhen?: string | null;
53
+ }
54
+
55
+ const path = (username: string) => `/users/${encodeURIComponent(username)}`;
56
+
57
+ export const getAllUsers = (api: ApiClient): Promise<User[]> => api.get("/users");
58
+
59
+ export const createUser = (api: ApiClient, user: NewUser): Promise<User> => api.post("/users", user);
60
+
61
+ export const createToolchain = (
62
+ api: ApiClient,
63
+ toolchain: { username: string; fullName: string | null },
64
+ ): Promise<User> => api.post("/users/toolchains", toolchain);
65
+
66
+ export const updateUser = (
67
+ api: ApiClient,
68
+ username: string,
69
+ changes: { email?: string | null; fullName?: string | null },
70
+ ): Promise<User> => api.patch(path(username), changes);
71
+
72
+ export const setPassword = (api: ApiClient, username: string, password: string): Promise<unknown> =>
73
+ api.put(`${path(username)}/password`, { password });
74
+
75
+ export const setAdmin = (api: ApiClient, username: string, admin: boolean): Promise<User> =>
76
+ api.put(`${path(username)}/admin`, { admin });
77
+
78
+ export const setDisabled = (api: ApiClient, username: string, disabled: boolean): Promise<User> =>
79
+ api.put(`${path(username)}/disabled`, { disabled });
80
+
81
+ export const endSessions = (api: ApiClient, username: string): Promise<void> => api.post(`${path(username)}/logout-all`);
82
+
83
+ export const getTokens = (api: ApiClient, username: string): Promise<AccessToken[]> => api.get(`${path(username)}/tokens`);
84
+
85
+ /** The answer has the token itself, the only time it is seen */
86
+ export const createToken = (
87
+ api: ApiClient,
88
+ username: string,
89
+ token: { name: string; scope: "read" | "write"; expiresDays: number | null },
90
+ ): Promise<AccessToken & { token: string }> => api.post(`${path(username)}/tokens`, token);
91
+
92
+ export const revokeToken = (api: ApiClient, username: string, id: string): Promise<void> =>
93
+ api.delete(`${path(username)}/tokens/${encodeURIComponent(id)}`);
94
+
95
+ export const getUsers = (api: ApiClient): Promise<UserSummary[]> => api.get("/users/directory");
96
+
97
+ /** What the user has made or changed, the most recent first */
98
+ export const getUserItems = (
99
+ api: ApiClient,
100
+ username: string,
101
+ options: { page: number; pageSize: number },
102
+ ): Promise<UserItems> =>
103
+ api.get(`/users/${encodeURIComponent(username)}/items`, { page: options.page, page_size: options.pageSize });
@@ -0,0 +1,85 @@
1
+ import { PageTitle, RequireLogin, useApi, useComponent, useTranslations, PageFrame, firstParam, Pager, readableTime } from "@pangloss/interface-core";
2
+ import { useNavigate, useParams, useSearchParams } from "@solidjs/router";
3
+ import { createMemo, Errored, For, Loading, Show } from "solid-js";
4
+ import { getUserItems } from "../api";
5
+
6
+ /** How many items a page has */
7
+ export const ITEMS_PAGE_SIZE = 25;
8
+
9
+ /** What one user has made or changed, a page of it */
10
+ function UserItemList(props: { username: string; page: number; onPage: (page: number) => void }) {
11
+ const ReferenceChip = useComponent("ReferenceChip");
12
+ const api = useApi();
13
+ const { t, language } = useTranslations();
14
+ const items = createMemo(() => getUserItems(api, props.username, { page: props.page, pageSize: ITEMS_PAGE_SIZE }));
15
+ const pages = () => Math.max(1, Math.ceil(items().count / ITEMS_PAGE_SIZE));
16
+ return (
17
+ <>
18
+ <PageTitle section={props.username} />
19
+ <h1 class="mb-6 flex items-baseline gap-3 border-b-[0.5px] border-slate-400/70 pt-1 pb-2 text-2xl font-semibold">
20
+ {items().user.username}
21
+ <Show when={items().user.fullName}>
22
+ <span class="text-base font-normal text-slate-600">{items().user.fullName}</span>
23
+ </Show>
24
+ </h1>
25
+ <Show
26
+ when={items().results.length > 0}
27
+ fallback={<p class="py-8 text-center text-slate-500">{t("users_no_items", "Nothing made or changed yet")}</p>}
28
+ >
29
+ <ul>
30
+ <For each={items().results}>
31
+ {(item) => (
32
+ <li
33
+ class="flex items-center justify-between gap-4 border-b-[0.5px] border-slate-300 py-1.5"
34
+ data-testid="user-item"
35
+ >
36
+ <div class="min-w-0">
37
+ <ReferenceChip
38
+ type={item.type}
39
+ label={item.label ?? item.id}
40
+ href={`/${item.type}/${encodeURIComponent(item.id)}`}
41
+ />
42
+ </div>
43
+ <span class="shrink-0 text-xs text-slate-600">
44
+ <Show when={item.action === "created"} fallback={t("modified", "Modified")}>
45
+ {t("created", "Created")}
46
+ </Show>
47
+ {" · "}
48
+ {readableTime(item.when, language())}
49
+ </span>
50
+ </li>
51
+ )}
52
+ </For>
53
+ </ul>
54
+ <Pager page={props.page} pages={pages()} onPage={props.onPage} />
55
+ </Show>
56
+ </>
57
+ );
58
+ }
59
+
60
+ /** A user and what they have made or changed, the most recent first: `/users/:username`, for someone logged in */
61
+ export default function UserPage() {
62
+ const Console = useComponent("Console");
63
+ const ErrorMessage = useComponent("ErrorMessage");
64
+ const navigate = useNavigate();
65
+ const params = useParams<{ username: string }>();
66
+ const [search, setSearch] = useSearchParams();
67
+ const { t } = useTranslations();
68
+ const page = () => Math.max(1, Number.parseInt(firstParam(search.page) ?? "1", 10) || 1);
69
+ return (
70
+ <RequireLogin onCancel={() => navigate("/", { replace: true })}>
71
+ <PageFrame>
72
+ <Console type={t("users_user", "User")} label={params.username} />
73
+ <Errored fallback={(error) => <ErrorMessage error={error()} />}>
74
+ <Loading fallback={<p>{t("loading", "Loading…")}</p>}>
75
+ <UserItemList
76
+ username={params.username}
77
+ page={page()}
78
+ onPage={(next) => setSearch({ page: next > 1 ? String(next) : undefined })}
79
+ />
80
+ </Loading>
81
+ </Errored>
82
+ </PageFrame>
83
+ </RequireLogin>
84
+ );
85
+ }