Skip to content

Commit

Permalink
Merge pull request #7 from Iconica-Development/rbac_view
Browse files Browse the repository at this point in the history
feat: add rbac_view to manage permission in app
  • Loading branch information
Gorter-dev committed Mar 28, 2024
2 parents cd6c365 + 401ca5d commit b920bf6
Show file tree
Hide file tree
Showing 43 changed files with 3,988 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.0

- Added rbac view, a rbac management package.
- Fixed some minor issues.

## 2.0.0

- Added the account group functionality.
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,49 @@ From here the following methods can be called from this service to set up and us
- getPermissionGroupsOfAccount(String accountId, String objectId): Retrieves the permission groups associated with an account for a specific object.
- getPermissionsOfAccount(String accountId, String objectId): Retrieves the permissions associated with an account for a specific object.

## View: Screens and Corresponding onTap Routes
#### AccountOverviewScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapObjects**: Navigate to ObjectOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen
- **onTapAccount**: Navigate to AccountDetailScreen with specific account ID
- **onTapAccountGroup**: Navigate to AccountGroupScreen with specific group ID

#### AccountDetailScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapObjects**: Navigate to ObjectOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen
- **onBack**: Navigate back

#### AccountGroupScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapObjects**: Navigate to ObjectOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen
- **onBack**: Navigate back

#### PermissionOverviewScreen
- **onTapAccounts**: Navigate to AccountOverviewScreen
- **onTapObjects**: Navigate to ObjectOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen

#### ObjectOverviewScreen
- **onTapAccounts**: Navigate to AccountOverviewScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen
- **onTapObject**: Navigate to ObjectDetailScreen with specific object ID

#### ObjectDetailScreen
- **onTapAccounts**: Navigate to AccountOverviewScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapCreateLink**: Navigate to CreateLinkScreen
- **onBack**: Navigate back

#### CreateLinkScreen
- **onTapAccounts**: Navigate to AccountOverviewScreen
- **onTapPermissions**: Navigate to PermissionOverviewScreen
- **onTapObjects**: Navigate to ObjectOverviewScreen
- **onBack**: Navigate back

## Issues

Please file any issues, bugs or feature request as an issue on our [GitHub](https://github.com/Iconica-Development/flutter_rbac_service/pulls) page. Commercial support is available if you need help with integration with your app or services. You can contact us at [support@iconica.nl](mailto:support@iconica.nl).
Expand Down
41 changes: 25 additions & 16 deletions packages/flutter_rbac_service/lib/src/services/rbac_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,23 @@ class RbacService {
///
/// Returns a [Future] that completes with the created [AccountGroupModel].
Future<AccountGroupModel> createAccountGroup(
String id,
String name,
Set<String> accountIds,
) async {
var group = AccountGroupModel(id: id, name: name, accountIds: accountIds);
var foundGroup = await _dataInterface.getAccountGroupByName(name);

if (foundGroup != null) {
debugPrint('Account group already exists: (ID: ${foundGroup.id},'
' Name: ${foundGroup.name})');

return foundGroup;
}

var group = AccountGroupModel(
id: _uuid.v4(),
name: name,
accountIds: accountIds,
);
await _dataInterface.setAccountGroup(group);

return group;
Expand Down Expand Up @@ -258,6 +269,11 @@ class RbacService {
) async =>
_dataInterface.getAccountGroupByName(accountGroupName);

Future<List<AccountGroupModel>> getAccountGroupsByAccountIds(
List<String> accountIds,
) async =>
_dataInterface.getAccountGroupsByAccountIds(accountIds);

/// Retrieves all account groups.
///
/// Retrieves and returns a list of all account groups stored in the data
Expand Down Expand Up @@ -492,26 +508,19 @@ class RbacService {

// Permission Groups /////////////////////////////////////////////////////////

/// Creates a new permission group.
///
/// Creates a new permission group with the specified [name] and
/// [permissionIds].
/// If a permission group with the same name already exists, returns the
/// existing group.
///
/// Returns a [Future] that completes with the created [PermissionGroupModel].
Future<PermissionGroupModel> createPermissionGroup(
String name,
Set<String> permissionIds,
) async {
var foundGroup = await _dataInterface.getPermissionGroupByName(name);
var foundGroup = await _dataInterface
.getPermissionGroupsByPermissionIds(permissionIds.toList());

if (foundGroup != null) {
debugPrint('Permission group already exists: (ID: ${foundGroup.id},'
' Name: ${foundGroup.name},'
' PermissionIDs: ${foundGroup.permissionIds})');
if (foundGroup.isNotEmpty) {
debugPrint('Permission group already exists: (ID: ${foundGroup.first.id},'
' Name: ${foundGroup.first.name},'
' PermissionIDs: ${foundGroup.first.permissionIds})');

return foundGroup;
return foundGroup.first;
}

var group = PermissionGroupModel(
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_rbac_service/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_rbac_service
description: A new Flutter package project.
version: 2.0.0
version: 2.1.0
publish_to: "none"

environment:
Expand All @@ -14,7 +14,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_rbac
path: packages/flutter_rbac_service_data_interface
ref: 2.0.0
ref: 2.1.0
uuid: ^4.3.3

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_rbac_service_data_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_rbac_service_data_interface
description: A new Flutter package project.
version: 2.0.0
version: 2.1.0
publish_to: "none"

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class FirebaseRbacDatasource implements RbacDataInterface {
List<String> permissionIds,
) async {
var snapshot = await _permissionGroupCollection
.where('permissions_ids', arrayContainsAny: permissionIds)
.where('permission_ids', arrayContainsAny: permissionIds)
.get();

return snapshot.docs.map((s) => s.data()).toList();
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_rbac_service_firebase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_rbac_service_firebase
description: A new Flutter package project.
version: 2.0.0
version: 2.1.0
publish_to: "none"

environment:
Expand All @@ -16,7 +16,7 @@ dependencies:
git:
url: https://github.com/Iconica-Development/flutter_rbac
path: packages/flutter_rbac_service_data_interface
ref: 2.0.0
ref: 2.1.0

dev_dependencies:
flutter_test:
Expand Down
30 changes: 30 additions & 0 deletions packages/flutter_rbac_view/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
1 change: 1 addition & 0 deletions packages/flutter_rbac_view/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
9 changes: 9 additions & 0 deletions packages/flutter_rbac_view/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include: package:flutter_iconica_analysis/analysis_options.yaml

# Possible to overwrite the rules from the package

analyzer:
exclude:

linter:
rules:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions packages/flutter_rbac_view/lib/flutter_rbac_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Package to manage the RBAC system.
library flutter_rbac_view;

export 'src/screens/accounts/account_detail.dart';
export 'src/screens/accounts/account_group.dart';
export 'src/screens/accounts/account_overview.dart';
export 'src/screens/create_link/create_link.dart';
export 'src/screens/objects/object_detail.dart';
export 'src/screens/objects/object_overview.dart';
export 'src/screens/permissions/permission_overview.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SelectableDialogItem {
SelectableDialogItem({required this.id, required this.title});

final String id;
final String title;
}
Loading

0 comments on commit b920bf6

Please sign in to comment.