merge fixes

This commit is contained in:
Stephan D
2025-11-23 15:45:10 +01:00
228 changed files with 5100 additions and 5433 deletions

View File

@@ -1,36 +1,35 @@
import 'package:flutter/foundation.dart';
import 'package:pshared/models/account/base.dart';
import 'package:pshared/models/describable.dart';
@immutable
class Account extends AccountBase {
final String login;
final String locale;
const Account({
required super.storable,
required super.describable,
required super.avatarUrl,
required super.lastName,
required this.login,
required super.locale,
required super.name,
required this.locale,
});
factory Account.fromBase(AccountBase accountBase, String login) => Account(
storable: accountBase.storable,
avatarUrl: accountBase.avatarUrl,
locale: accountBase.locale,
name: accountBase.name,
login: login,
);
@override
Account copyWith({
Describable? describable,
String? lastName,
String? Function()? avatarUrl,
String? name,
String? locale,
}) {
final updatedBase = super.copyWith(
avatarUrl: avatarUrl,
name: name,
locale: locale,
);
return Account.fromBase(updatedBase, login);
}
}) => Account(
storable: storable,
describable: describableCopyWithOther(this.describable, describable),
lastName: lastName ?? this.lastName,
avatarUrl: avatarUrl != null ? avatarUrl() : this.avatarUrl,
login: login,
locale: locale ?? this.locale,
);
}

View File

@@ -1,8 +1,16 @@
import 'package:flutter/foundation.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/storable.dart';
import 'package:pshared/models/storable/describable.dart';
import 'package:pshared/utils/name_initials.dart';
class AccountBase implements Storable {
@immutable
class AccountBase implements StorableDescribable {
final Storable storable;
final Describable describable;
final String lastName;
@override
String get id => storable.id;
@@ -10,26 +18,30 @@ class AccountBase implements Storable {
DateTime get createdAt => storable.createdAt;
@override
DateTime get updatedAt => storable.updatedAt;
@override
String get name => describable.name;
@override
String? get description => describable.description;
final String? avatarUrl;
final String name;
final String locale;
const AccountBase({
required this.storable,
required this.name,
required this.locale,
required this.describable,
required this.avatarUrl,
required this.lastName,
});
String get nameInitials => getNameInitials(describable.name);
AccountBase copyWith({
Describable? describable,
String? lastName,
String? Function()? avatarUrl,
String? name,
String? locale,
}) => AccountBase(
storable: storable,
avatarUrl: avatarUrl != null ? avatarUrl() : this.avatarUrl,
locale: locale ?? this.locale,
name: name ?? this.name,
describable: describable ?? this.describable,
lastName: lastName ?? this.lastName,
);
}

View File

@@ -0,0 +1,17 @@
import 'package:pshared/models/account/account.dart';
import 'package:pshared/models/auth/pending_login.dart';
class LoginOutcome {
final Account? account;
final PendingLogin? pending;
const LoginOutcome._({this.account, this.pending});
factory LoginOutcome.completed(Account account) => LoginOutcome._(account: account);
factory LoginOutcome.pending(PendingLogin pending) => LoginOutcome._(pending: pending);
bool get isPending => pending != null;
bool get isCompleted => account != null;
}

View File

@@ -0,0 +1,33 @@
import 'package:pshared/api/responses/login_pending.dart';
import 'package:pshared/api/responses/token.dart';
import 'package:pshared/data/mapper/account/account.dart';
import 'package:pshared/models/account/account.dart';
import 'package:pshared/models/session_identifier.dart';
class PendingLogin {
final Account account;
final TokenData pendingToken;
final String destination;
final int ttlSeconds;
final SessionIdentifier session;
const PendingLogin({
required this.account,
required this.pendingToken,
required this.destination,
required this.ttlSeconds,
required this.session,
});
factory PendingLogin.fromResponse(
PendingLoginResponse response, {
required SessionIdentifier session,
}) => PendingLogin(
account: response.account.account.toDomain(),
pendingToken: response.pendingToken,
destination: response.destination,
ttlSeconds: response.ttlSeconds,
session: session,
);
}

View File

@@ -0,0 +1,39 @@
import 'package:flutter/foundation.dart';
abstract class Describable {
String get name;
String? get description;
}
@immutable
class _DescribableImp implements Describable {
@override
final String name;
@override
final String? description;
const _DescribableImp({
required this.name,
required this.description,
});
}
Describable newDescribable({required String name, String? description}) =>
_DescribableImp(name: name, description: description);
extension DescribableCopier on Describable {
Describable copyWith({
String? name,
String? Function()? description,
}) => newDescribable(
name: name ?? this.name,
description: description != null ? description() : this.description,
);
}
Describable describableCopyWithOther(Describable current, Describable? other) => current.copyWith(
name: other?.name,
description: () => other?.description,
);

View File

@@ -0,0 +1,18 @@
import 'package:flutter/foundation.dart';
abstract class OrganizationBound {
String get organizationRef;
}
@immutable
class _OrganizationBoundImp implements OrganizationBound {
@override
final String organizationRef;
const _OrganizationBoundImp({
required this.organizationRef,
});
}
OrganizationBound newOrganizationBound({ required String organizationRef }) => _OrganizationBoundImp(organizationRef: organizationRef);

View File

@@ -1,7 +1,12 @@
import 'package:pshared/models/describable.dart';
class OrganizationDescription {
final Describable description;
final String? logoUrl;
const OrganizationDescription({
required this.description,
this.logoUrl,
});
}

View File

@@ -1,8 +1,13 @@
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/permissions/bound.dart';
import 'package:pshared/models/permissions/bound/describable.dart';
import 'package:pshared/models/storable.dart';
class Organization implements Storable {
class Organization implements PermissionBoundStorableDescribable {
final Storable storable;
final PermissionBound permissionBound;
final Describable describable;
@override
String get id => storable.id;
@@ -10,25 +15,39 @@ class Organization implements Storable {
DateTime get createdAt => storable.createdAt;
@override
DateTime get updatedAt => storable.updatedAt;
@override
String get organizationRef => permissionBound.organizationRef;
@override
String get permissionRef => permissionBound.permissionRef;
@override
String get name => describable.name;
@override
String? get description => describable.description;
final String timeZone;
final String? logoUrl;
final String tenantRef;
const Organization({
required this.storable,
required this.describable,
required this.timeZone,
required this.permissionBound,
required this.tenantRef,
this.logoUrl,
});
Organization copyWith({
String? name,
String? Function()? description,
Describable? describable,
String? timeZone,
String? Function()? logoUrl,
}) => Organization(
storable: storable, // Same Storable, same id
describable: describableCopyWithOther(this.describable, describable),
timeZone: timeZone ?? this.timeZone,
logoUrl: logoUrl != null ? logoUrl() : this.logoUrl,
permissionBound: permissionBound,
tenantRef: tenantRef,
);
}

View File

@@ -1,22 +0,0 @@
import 'package:pshared/config/constants.dart';
abstract class PermissionBound {
String get permissionRef;
String get organizationRef;
}
class _PermissionBoundImp implements PermissionBound {
@override
final String permissionRef;
@override
final String organizationRef;
const _PermissionBoundImp({
required this.permissionRef,
required this.organizationRef,
});
}
PermissionBound newPermissionBound({ required String organizationRef, String? permissionRef}) =>
_PermissionBoundImp(permissionRef: permissionRef ?? Constants.nilObjectRef, organizationRef: organizationRef);

View File

@@ -0,0 +1,32 @@
import 'package:flutter/foundation.dart';
import 'package:pshared/config/constants.dart';
import 'package:pshared/models/organization/bound.dart';
abstract class PermissionBound extends OrganizationBound {
String get permissionRef;
}
@immutable
class _PermissionBoundImp implements PermissionBound {
@override
final String permissionRef;
final OrganizationBound organizationBound;
@override
get organizationRef => organizationBound.organizationRef;
const _PermissionBoundImp({
required this.permissionRef,
required this.organizationBound,
});
}
PermissionBound newPermissionBound({
required OrganizationBound organizationBound,
String? permissionRef,
}) => _PermissionBoundImp(
permissionRef: permissionRef ?? Constants.nilObjectRef,
organizationBound: organizationBound,
);

View File

@@ -0,0 +1,6 @@
import 'package:pshared/models/permissions/bound/storable.dart';
import 'package:pshared/models/storable/describable.dart';
abstract class PermissionBoundStorableDescribable implements PermissionBoundStorable, StorableDescribable {
}

View File

@@ -1,4 +1,4 @@
import 'package:pshared/models/permission_bound.dart';
import 'package:pshared/models/permissions/bound.dart';
import 'package:pshared/models/storable.dart';

View File

@@ -1,9 +1,12 @@
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/resources.dart';
import 'package:pshared/models/storable.dart';
import 'package:pshared/models/storable/describable.dart';
class PolicyDescription implements Storable {
class PolicyDescription implements StorableDescribable {
final Storable storable;
final Describable describable;
final List<ResourceType>? resourceTypes;
final String? organizationRef;
@@ -13,9 +16,14 @@ class PolicyDescription implements Storable {
DateTime get createdAt => storable.createdAt;
@override
DateTime get updatedAt => storable.updatedAt;
@override
String get name => describable.name;
@override
String? get description => describable.description;
const PolicyDescription({
required this.storable,
required this.describable,
required this.resourceTypes,
required this.organizationRef,
});

View File

@@ -1,8 +1,11 @@
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/storable.dart';
import 'package:pshared/models/storable/describable.dart';
class RoleDescription implements Storable {
class RoleDescription implements StorableDescribable {
final Storable storable;
final Describable describable;
@override
String get id => storable.id;
@@ -10,18 +13,25 @@ class RoleDescription implements Storable {
DateTime get createdAt => storable.createdAt;
@override
DateTime get updatedAt => storable.updatedAt;
@override
String get name => describable.name;
@override
String? get description => describable.description;
final String organizationRef;
const RoleDescription({
required this.storable,
required this.describable,
required this.organizationRef,
});
factory RoleDescription.build({
required Describable roleDescription,
required String organizationRef,
}) => RoleDescription(
storable: newStorable(),
describable: roleDescription,
organizationRef: organizationRef
);
}

View File

@@ -0,0 +1,22 @@
abstract class Reference {
String get ref;
}
class _ReferenceImp implements Reference {
@override
final String ref;
const _ReferenceImp({
required this.ref,
});
}
Reference newReference({required String ref}) => _ReferenceImp(ref: ref);
extension ReferenceCopier on Reference {
Reference copyWith({
String? ref,
}) => newReference(
ref: ref ?? this.ref,
);
}

View File

@@ -0,0 +1,18 @@
import 'package:json_annotation/json_annotation.dart';
part 'session_identifier.g.dart';
@JsonSerializable()
class SessionIdentifier {
final String clientId;
final String deviceId;
const SessionIdentifier({
required this.clientId,
required this.deviceId,
});
factory SessionIdentifier.fromJson(Map<String, dynamic> json) => _$SessionIdentifierFromJson(json);
Map<String, dynamic> toJson() => _$SessionIdentifierToJson(this);
}

View File

@@ -1,4 +1,6 @@
import 'package:pshared/config/constants.dart';
import 'package:flutter/foundation.dart';
import 'package:pshared/config/web.dart';
abstract class Storable {
@@ -7,6 +9,7 @@ abstract class Storable {
DateTime get updatedAt;
}
@immutable
class _StorableImp implements Storable {
@override
final String id;

View File

@@ -0,0 +1,6 @@
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/storable.dart';
abstract class StorableDescribable implements Storable, Describable {
}