Merge pull request 'Sender Invitation' (#245) from SEND024 into main
All checks were successful
ci/woodpecker/push/gateway_tgsettle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/discovery Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/gateway_mntx Pipeline was successful
ci/woodpecker/push/gateway_chain Pipeline was successful
All checks were successful
ci/woodpecker/push/gateway_tgsettle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/discovery Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/gateway_mntx Pipeline was successful
ci/woodpecker/push/gateway_chain Pipeline was successful
Reviewed-on: #245 Reviewed-by: tech <tech.sendico@proton.me>
This commit was merged in pull request #245.
This commit is contained in:
111
frontend/pshared/lib/models/invitation/invitation.dart
Normal file
111
frontend/pshared/lib/models/invitation/invitation.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:pshared/models/organization/bound.dart';
|
||||
import 'package:pshared/models/permissions/bound.dart';
|
||||
import 'package:pshared/models/permissions/bound/storable.dart';
|
||||
import 'package:pshared/models/storable.dart';
|
||||
import 'package:pshared/models/invitation/status.dart';
|
||||
|
||||
|
||||
class InvitationContent {
|
||||
final String email;
|
||||
final String name;
|
||||
final String comment;
|
||||
|
||||
const InvitationContent({
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.comment,
|
||||
});
|
||||
|
||||
InvitationContent copyWith({
|
||||
String? email,
|
||||
String? name,
|
||||
String? comment,
|
||||
}) => InvitationContent(
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
comment: comment ?? this.comment,
|
||||
);
|
||||
}
|
||||
|
||||
class Invitation implements PermissionBoundStorable {
|
||||
final Storable storable;
|
||||
final PermissionBound permissionBound;
|
||||
final String roleRef;
|
||||
final String inviterRef;
|
||||
final InvitationStatus status;
|
||||
final DateTime expiresAt;
|
||||
final InvitationContent content;
|
||||
final bool isArchived;
|
||||
|
||||
Invitation({
|
||||
required this.storable,
|
||||
required this.permissionBound,
|
||||
required this.roleRef,
|
||||
required this.inviterRef,
|
||||
required this.status,
|
||||
required this.expiresAt,
|
||||
required this.content,
|
||||
this.isArchived = false,
|
||||
});
|
||||
|
||||
@override
|
||||
String get id => storable.id;
|
||||
@override
|
||||
DateTime get createdAt => storable.createdAt;
|
||||
@override
|
||||
DateTime get updatedAt => storable.updatedAt;
|
||||
|
||||
@override
|
||||
String get permissionRef => permissionBound.permissionRef;
|
||||
@override
|
||||
String get organizationRef => permissionBound.organizationRef;
|
||||
|
||||
String get inviteeDisplayName => content.name.isNotEmpty ? content.name : content.email;
|
||||
bool get isExpired => expiresAt.isBefore(DateTime.now().toUtc());
|
||||
bool get isPending => status == InvitationStatus.created || status == InvitationStatus.sent;
|
||||
|
||||
Invitation copyWith({
|
||||
Storable? storable,
|
||||
PermissionBound? permissionBound,
|
||||
String? roleRef,
|
||||
String? inviterRef,
|
||||
InvitationStatus? status,
|
||||
DateTime? expiresAt,
|
||||
InvitationContent? content,
|
||||
bool? isArchived,
|
||||
}) => Invitation(
|
||||
storable: storable ?? this.storable,
|
||||
permissionBound: permissionBound ?? this.permissionBound,
|
||||
roleRef: roleRef ?? this.roleRef,
|
||||
inviterRef: inviterRef ?? this.inviterRef,
|
||||
status: status ?? this.status,
|
||||
expiresAt: expiresAt ?? this.expiresAt,
|
||||
content: content ?? this.content,
|
||||
isArchived: isArchived ?? this.isArchived,
|
||||
);
|
||||
}
|
||||
|
||||
Invitation newInvitation({
|
||||
required String organizationRef,
|
||||
required String roleRef,
|
||||
required String inviterRef,
|
||||
required String email,
|
||||
String name = '',
|
||||
String comment = '',
|
||||
InvitationStatus status = InvitationStatus.created,
|
||||
DateTime? expiresAt,
|
||||
bool isArchived = false,
|
||||
String? permissionRef,
|
||||
}) => Invitation(
|
||||
storable: newStorable(),
|
||||
permissionBound: newPermissionBound(
|
||||
organizationBound: newOrganizationBound(organizationRef: organizationRef),
|
||||
permissionRef: permissionRef,
|
||||
),
|
||||
roleRef: roleRef,
|
||||
inviterRef: inviterRef,
|
||||
status: status,
|
||||
expiresAt: expiresAt ?? DateTime.now().toUtc().add(const Duration(days: 7)),
|
||||
content: InvitationContent(email: email, name: name, comment: comment),
|
||||
isArchived: isArchived,
|
||||
);
|
||||
7
frontend/pshared/lib/models/invitation/status.dart
Normal file
7
frontend/pshared/lib/models/invitation/status.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
enum InvitationStatus {
|
||||
created,
|
||||
sent,
|
||||
accepted,
|
||||
declined,
|
||||
revoked,
|
||||
}
|
||||
Reference in New Issue
Block a user