actions-test/lib/backend/permissions.dart
Jakob Meier eba0790f7c
More bug fixes (see description)
- Fixed bug where opening room would show null-error,
  for a couple of seconds.
  This was caused by the FAB not checking if widget.info!=null

- Added try&catch for item category,
  to prevent index-out-of-bounds when the item uses a category
  that no longer exists

- Renamed add/remove Articles to fit the new name: ShoppingListItem
2023-04-05 09:23:41 +02:00

150 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.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 addShoppingListItems {
return oB("0000001");
}
static int get removeShoppingListItems {
return oB("0000010");
}
static int get editRoomContent {
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 [
addShoppingListItems,
removeShoppingListItems,
editRoomContent,
changeMeta,
ota,
changeAdmin,
manageMembers
];
}
static String name(int permission, BuildContext context) {
final trans = AppLocalizations.of(context);
switch (permission) {
case 1:
return trans!.roomPermissionAddItems;
case 2:
return trans!.roomPermissionRemoveItems;
case 4:
return trans!.roomPermissionEditContent;
case 8:
return trans!.roomPermissionChangeMeta;
case 16:
return trans!.roomPermissionManageOTA;
case 32:
return trans!.roomPermissionManageAdmins;
case 64:
return trans!.roomPermissionManageMembers;
}
return trans!.roomPermissionUnknown;
}
static String describe(int permission, BuildContext context) {
final trans = AppLocalizations.of(context);
switch (permission) {
case 1:
return trans!.roomPermissionAddItemsSubtitle;
case 2:
return trans!.roomPermissionRemoveItemsSubtitle;
case 4:
return trans!.roomPermissionEditContentSubtitle;
case 8:
return trans!.roomPermissionChangeMetaSubtitle;
case 16:
return trans!.roomPermissionManageOTASubtitle;
case 32:
return trans!.roomPermissionManageAdminsSubtitle;
case 64:
return trans!.roomPermissionManageMembersSubtitle;
}
return trans!.roomPermissionUnknownSubtitle;
}
}