2023-03-29 15:14:27 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2023-03-22 21:07:29 +01:00
|
|
|
// 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) {
|
2023-03-23 10:19:36 +01:00
|
|
|
return int.parse(binary, radix: 2);
|
2023-03-22 21:07:29 +01:00
|
|
|
}
|
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
class ServerPermission {
|
|
|
|
static int get none {
|
|
|
|
return oB("0000000000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
// default permission set
|
|
|
|
static int get def {
|
|
|
|
return oB("0000000000000011");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get canUseAPI {
|
|
|
|
return oB("0000000000000001");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get provideCert {
|
|
|
|
return oB("0000000000000010");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get manageOTA {
|
|
|
|
return oB("0000010000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get manageServerProductList {
|
|
|
|
return oB("0000100000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get viewUsersAndLists {
|
|
|
|
return oB("0001000000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get editSettings {
|
|
|
|
return oB("0010000000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get editPermissions {
|
|
|
|
return oB("0100000000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get editUsers {
|
|
|
|
return oB("1000000000000000");
|
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
|
|
|
static int get allManagement {
|
|
|
|
return oB("1111110000000000");
|
|
|
|
}
|
|
|
|
|
2023-03-23 10:19:36 +01:00
|
|
|
static int get all {
|
|
|
|
return oB("1111111111111111");
|
|
|
|
}
|
|
|
|
}
|
2023-03-22 21:07:29 +01:00
|
|
|
|
|
|
|
class RoomPermission {
|
|
|
|
static int get addArticles {
|
|
|
|
return oB("0000001");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get removeArticles {
|
|
|
|
return oB("0000010");
|
|
|
|
}
|
|
|
|
|
2023-03-29 18:47:45 +02:00
|
|
|
static int get listCategoriesAndProducts {
|
2023-03-22 21:07:29 +01:00
|
|
|
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");
|
|
|
|
}
|
2023-03-25 10:27:21 +01:00
|
|
|
|
|
|
|
static List<int> get asList {
|
|
|
|
return [
|
|
|
|
addArticles,
|
|
|
|
removeArticles,
|
2023-03-29 18:47:45 +02:00
|
|
|
listCategoriesAndProducts,
|
2023-03-25 10:27:21 +01:00
|
|
|
changeMeta,
|
|
|
|
ota,
|
|
|
|
changeAdmin,
|
|
|
|
manageMembers
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-03-29 15:14:27 +02:00
|
|
|
static String name(int permission, BuildContext context) {
|
|
|
|
final trans = AppLocalizations.of(context);
|
|
|
|
|
2023-03-25 10:27:21 +01:00
|
|
|
switch (permission) {
|
|
|
|
case 1:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionAddArticles;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 2:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionRemoveArticles;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 4:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionList;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 8:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionChangeMeta;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 16:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageOTA;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 32:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageAdmins;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 64:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageMembers;
|
2023-03-25 10:27:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionUnknown;
|
2023-03-25 10:27:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-29 15:14:27 +02:00
|
|
|
static String describe(int permission, BuildContext context) {
|
|
|
|
final trans = AppLocalizations.of(context);
|
|
|
|
|
2023-03-25 10:27:21 +01:00
|
|
|
switch (permission) {
|
|
|
|
case 1:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionAddArticlesSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 2:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionRemoveArticlesSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 4:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionListSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 8:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionChangeMetaSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 16:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageOTASubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 32:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageAdminsSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
case 64:
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionManageMembersSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
}
|
|
|
|
|
2023-03-29 15:14:27 +02:00
|
|
|
return trans!.roomPermissionUnknownSubtitle;
|
2023-03-25 10:27:21 +01:00
|
|
|
}
|
2023-03-22 21:07:29 +01:00
|
|
|
}
|