Added placeholder for lastName and role addition functionality
Try to rebase
This commit is contained in:
@@ -9,11 +9,15 @@ part 'invitation.g.dart';
|
||||
class InvitationContentDTO {
|
||||
final String email;
|
||||
final String name;
|
||||
@JsonKey(defaultValue: '')
|
||||
//TODO remove when backend will accept lastName
|
||||
final String lastName;
|
||||
final String comment;
|
||||
|
||||
const InvitationContentDTO({
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.lastName,
|
||||
required this.comment,
|
||||
});
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ extension InvitationModelMapper on Invitation {
|
||||
content: InvitationContentDTO(
|
||||
email: content.email,
|
||||
name: content.name,
|
||||
lastName: content.lastName,
|
||||
comment: content.comment,
|
||||
),
|
||||
isArchived: isArchived,
|
||||
@@ -40,6 +41,7 @@ extension InvitationDTOMapper on InvitationDTO {
|
||||
content: InvitationContent(
|
||||
email: content.email,
|
||||
name: content.name,
|
||||
lastName: content.lastName,
|
||||
comment: content.comment,
|
||||
),
|
||||
isArchived: isArchived,
|
||||
|
||||
@@ -8,23 +8,36 @@ import 'package:pshared/models/invitation/status.dart';
|
||||
class InvitationContent {
|
||||
final String email;
|
||||
final String name;
|
||||
final String lastName;
|
||||
final String comment;
|
||||
|
||||
const InvitationContent({
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.lastName,
|
||||
required this.comment,
|
||||
});
|
||||
|
||||
InvitationContent copyWith({
|
||||
String? email,
|
||||
String? name,
|
||||
String? lastName,
|
||||
String? comment,
|
||||
}) => InvitationContent(
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
lastName: lastName ?? this.lastName,
|
||||
comment: comment ?? this.comment,
|
||||
);
|
||||
|
||||
String get fullName {
|
||||
final trimmedName = name.trim();
|
||||
final trimmedLastName = lastName.trim();
|
||||
if (trimmedName.isEmpty && trimmedLastName.isEmpty) return '';
|
||||
if (trimmedName.isEmpty) return trimmedLastName;
|
||||
if (trimmedLastName.isEmpty) return trimmedName;
|
||||
return '$trimmedName $trimmedLastName';
|
||||
}
|
||||
}
|
||||
|
||||
class Invitation implements PermissionBoundStorable {
|
||||
@@ -60,7 +73,7 @@ class Invitation implements PermissionBoundStorable {
|
||||
@override
|
||||
String get organizationRef => permissionBound.organizationRef;
|
||||
|
||||
String get inviteeDisplayName => content.name.isNotEmpty ? content.name : content.email;
|
||||
String get inviteeDisplayName => content.fullName.isNotEmpty ? content.fullName : content.email;
|
||||
bool get isExpired => expiresAt.isBefore(DateTime.now().toUtc());
|
||||
bool get isPending => status == InvitationStatus.created || status == InvitationStatus.sent;
|
||||
|
||||
@@ -91,6 +104,7 @@ Invitation newInvitation({
|
||||
required String inviterRef,
|
||||
required String email,
|
||||
String name = '',
|
||||
String lastName = '',
|
||||
String comment = '',
|
||||
InvitationStatus status = InvitationStatus.created,
|
||||
DateTime? expiresAt,
|
||||
@@ -106,6 +120,6 @@ Invitation newInvitation({
|
||||
inviterRef: inviterRef,
|
||||
status: status,
|
||||
expiresAt: expiresAt ?? DateTime.now().toUtc().add(const Duration(days: 7)),
|
||||
content: InvitationContent(email: email, name: name, comment: comment),
|
||||
content: InvitationContent(email: email, name: name, lastName: lastName, comment: comment),
|
||||
isArchived: isArchived,
|
||||
);
|
||||
|
||||
@@ -30,6 +30,7 @@ class InvitationsProvider extends GenericProvider<Invitation> {
|
||||
required String roleRef,
|
||||
required String inviterRef,
|
||||
String name = '',
|
||||
String lastName = '',
|
||||
String comment = '',
|
||||
DateTime? expiresAt,
|
||||
}) async {
|
||||
@@ -39,6 +40,7 @@ class InvitationsProvider extends GenericProvider<Invitation> {
|
||||
inviterRef: inviterRef,
|
||||
email: email,
|
||||
name: name,
|
||||
lastName: lastName,
|
||||
comment: comment,
|
||||
expiresAt: expiresAt,
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import 'package:pshared/api/requests/change_role.dart';
|
||||
import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/permissions/access.dart';
|
||||
import 'package:pshared/models/permissions/action.dart' as perm;
|
||||
import 'package:pshared/models/permissions/data/permission.dart';
|
||||
@@ -101,6 +102,32 @@ class PermissionsProvider extends ChangeNotifier {
|
||||
return _performServiceCall(() => PermissionsService.deleteRoleDescription(descRef));
|
||||
}
|
||||
|
||||
Future<RoleDescription?> createRoleDescription({
|
||||
required String name,
|
||||
String? description,
|
||||
}) async {
|
||||
if (!_organizations.isOrganizationSet) {
|
||||
throw StateError('Organization is not set');
|
||||
}
|
||||
final normalizedName = name.trim();
|
||||
final normalizedDescription = description?.trim();
|
||||
final roleDescription = RoleDescription.build(
|
||||
organizationRef: _organizations.current.id,
|
||||
roleDescription: newDescribable(name: normalizedName, description: normalizedDescription),
|
||||
);
|
||||
|
||||
await _performServiceCall(() => PermissionsService.createRoleDescription(roleDescription));
|
||||
final matches = roleDescriptions.where(
|
||||
(role) =>
|
||||
role.organizationRef == _organizations.current.id &&
|
||||
role.name == normalizedName &&
|
||||
(role.description ?? '') == (normalizedDescription ?? ''),
|
||||
).toList()
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
|
||||
return matches.isEmpty ? null : matches.first;
|
||||
}
|
||||
|
||||
Future<UserAccess?> createPermissions(List<Policy> policies) {
|
||||
return _performServiceCall(() => PermissionsService.createPolicies(policies));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import 'package:pshared/api/requests/change_role.dart';
|
||||
import 'package:pshared/api/requests/permissions/change_policies.dart';
|
||||
import 'package:pshared/api/responses/policies.dart';
|
||||
import 'package:pshared/data/mapper/permissions/data/permissions.dart';
|
||||
import 'package:pshared/data/mapper/permissions/descriptions/role.dart';
|
||||
import 'package:pshared/data/mapper/permissions/descriptions/description.dart';
|
||||
import 'package:pshared/models/permissions/descriptions/role.dart';
|
||||
import 'package:pshared/models/permissions/access.dart';
|
||||
import 'package:pshared/models/permissions/data/policy.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
@@ -35,6 +37,15 @@ class PermissionsService {
|
||||
await AuthorizationService.getDELETEResponse(_objectType, '/role/$roleDescriptionRef', {});
|
||||
}
|
||||
|
||||
static Future<void> createRoleDescription(RoleDescription roleDescription) async {
|
||||
_logger.fine('Creating role ${roleDescription.name}...');
|
||||
await AuthorizationService.getPOSTResponse(
|
||||
_objectType,
|
||||
'/role',
|
||||
roleDescription.toDTO().toJson(),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> createPolicies(List<Policy> policies) async {
|
||||
_logger.fine('Creating ${policies.length} policies...');
|
||||
await AuthorizationService.getPOSTResponse(
|
||||
|
||||
Reference in New Issue
Block a user