forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess.ts
More file actions
38 lines (32 loc) · 1.07 KB
/
Copy pathaccess.ts
File metadata and controls
38 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type Database from "better-sqlite3";
import {
decideUser,
getUser,
listPendingUsers,
upsertPendingUser,
} from "../db/client.js";
/**
* Doc section 9, "User Access Requests": a new person interacting with the
* bot doesn't automatically get access to controlled features - a request
* is created for the owner to accept or decline.
*/
export function requestAccess(db: Database.Database, userId: string, username?: string) {
upsertPendingUser(db, userId, username);
}
export function isApproved(db: Database.Database, userId: string): boolean {
const user = getUser(db, userId);
return user?.status === "approved";
}
export function hasPendingRequest(db: Database.Database, userId: string): boolean {
const user = getUser(db, userId);
return user?.status === "pending";
}
export function approve(db: Database.Database, userId: string) {
decideUser(db, userId, true);
}
export function decline(db: Database.Database, userId: string) {
decideUser(db, userId, false);
}
export function pendingRequests(db: Database.Database) {
return listPendingUsers(db);
}