actions-test/lib/backend/permissions.dart
Jakob Meier e3ca4fafa6
Added room default permission editor screen
The screen allows the user to change the default permission set,
that applies to every member (but not the owner nor the admins).

This screen is only accessible by the owner,
admins or members with the changeAdmin permission.
2023-03-25 10:31:28 +01:00

144 lines
2.9 KiB
Dart

// implementation of permission types
// according to the server permissions.ts
// https://codeberg.org/outbag/server/src/branch/dev/src/server/permissions.ts
// same as javascript 0b prefix
// pronounced o-b
int oB(String binary) {
return int.parse(binary, radix: 2);
}
class ServerPermission {
static int get none {
return oB("0000000000000000");
}
// default permission set
static int get def {
return oB("0000000000000011");
}
static int get canUseAPI {
return oB("0000000000000001");
}
static int get provideCert {
return oB("0000000000000010");
}
static int get manageOTA {
return oB("0000010000000000");
}
static int get manageServerProductList {
return oB("0000100000000000");
}
static int get viewUsersAndLists {
return oB("0001000000000000");
}
static int get editSettings {
return oB("0010000000000000");
}
static int get editPermissions {
return oB("0100000000000000");
}
static int get editUsers {
return oB("1000000000000000");
}
static int get allManagement {
return oB("1111110000000000");
}
static int get all {
return oB("1111111111111111");
}
}
class RoomPermission {
static int get addArticles {
return oB("0000001");
}
static int get removeArticles {
return oB("0000010");
}
static int get listGroupsItems {
return oB("0000100");
}
static int get changeMeta {
return oB("0001000");
}
static int get ota {
return oB("0010000");
}
static int get changeAdmin {
return oB("0100000");
}
static int get manageMembers {
return oB("1000000");
}
static List<int> get asList {
return [
addArticles,
removeArticles,
listGroupsItems,
changeMeta,
ota,
changeAdmin,
manageMembers
];
}
static String name(int permission) {
switch (permission) {
case 1:
return 'Add Articles';
case 2:
return 'Remove Articles';
case 4:
return 'List Groups and Items';
case 8:
return 'Change Room Metadata';
case 16:
return 'Manage OTAs';
case 32:
return 'Manage Admins';
case 64:
return 'Manage Members';
}
return "Unknown permission";
}
static String describe(int permission) {
switch (permission) {
case 1:
return 'Allows users to add items to the shopping list';
case 2:
return 'Allows users to remove items from the shopping list';
case 4:
return 'Allows the user to view groups and products';
case 8:
return 'Allows the user to edit the room name, description and icon';
case 16:
return 'Alloww the user to create, share and delete authentification tokens';
case 32:
return 'Allows the user to change the admin status of other members';
case 64:
return 'Allows the user to invite and kick room members';
}
return "No description available";
}
}