Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for private CloudFiles. #1150

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/lib/filesharing/file_sharing_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class FileSharingGateway {
IList<LocalFile> localFiles,
String courseID,
String authorID,
String authorName,
) async {
String authorName, {
bool isPrivate = false,
}) async {
final attachments = <String>[];
final hasAttachments = localFiles.isNotEmpty;
if (hasAttachments) {
Expand All @@ -67,6 +68,7 @@ class FileSharingGateway {
creatorName: authorName,
localFile: localFile,
path: FolderPath.attachments,
isPrivate: isPrivate,
);

final snapshot = await uploadTask.onComplete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class FirebaseFileUploader {
required String creatorID,
required String creatorName,
FolderPath path = FolderPath.root,
bool isPrivate = false,
}) async {
return implementation.uploadFile(
localFile: localFile,
courseID: courseID,
path: path,
creatorID: creatorID,
creatorName: creatorName,
isPrivate: isPrivate,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FirebaseFileUploaderImplementation {
required LocalFile localFile,
required String creatorID,
required String creatorName,
required isPrivate,
FolderPath path = FolderPath.root,
}) async {
final ref = filesCollection.doc();
Expand All @@ -36,6 +37,7 @@ class FirebaseFileUploaderImplementation {
creatorName: creatorName,
courseID: courseID,
path: path,
isPrivate: isPrivate,
).copyWith(
fileFormat: fileFormat,
forUsers: {creatorID: true},
Expand Down
6 changes: 6 additions & 0 deletions app/lib/filesharing/widgets/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Future<void> showCloudFileSheet({
icon: FileIcon(fileFormat: cloudFile.fileFormat),
creatorName: cloudFile.creatorName,
sizeBytes: cloudFile.sizeBytes,
isPrivate: cloudFile.isPrivate,
items: CloudFileActionsColumn(
hasPermissionToEdit: hasPermissionToEdit,
onSelectCloudFileAction: (context, sheetOption) =>
Expand All @@ -95,6 +96,7 @@ class FileSheet extends StatelessWidget {
this.fileType,
this.icon,
this.sizeBytes,
this.isPrivate,
}) : super(key: key);

final String? name;
Expand All @@ -103,6 +105,7 @@ class FileSheet extends StatelessWidget {
final FileFormat? fileType;
final Widget? icon;
final int? sizeBytes;
final bool? isPrivate;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -147,6 +150,9 @@ class FileSheet extends StatelessWidget {
"Ersteller: $creatorName",
style: greyTextStyle,
),
if (isPrivate == true)
Text('Privat (nur für dich sichtbar)',
style: greyTextStyle),
sizeBytes != null
? Text(
"Größe: ${KiloByteSize(bytes: sizeBytes!).inMegabytes.toStringAsFixed(2)} MB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ class HomeworkDialogApi {
final typeOfUser = user.typeOfUser;

final attachments = await _api.fileSharing.uploadAttachments(
localFiles, courseId.id, authorReference.id, authorName);
localFiles, courseId.id, authorReference.id, authorName,
isPrivate: userInput.private);

final homework = HomeworkDto.create(
courseReference: _api.references.getCourseReference(course.id),
Expand Down Expand Up @@ -855,6 +856,7 @@ class HomeworkDialogApi {
oldHomework.courseReference!.id,
editorID,
editorName,
isPrivate: userInput.private,
);
attachments.addAll(newAttachments);

Expand Down
1 change: 1 addition & 0 deletions app/test/homework/homework_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ CloudFile randomAttachmentCloudFileWith(
'Random Assignment Creator Name ${randomAlphaNumeric(5)}',
courseID: courseId,
creatorID: 'random_file_creator_id_${randomAlphaNumeric(5)}',
isPrivate: randomBool(),
path:
FolderPath.fromPathString('/$courseId/${FolderPath.attachments}'))
.copyWith(name: name, fileFormat: fileType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CloudFile {
final int? sizeBytes;
final FileFormat fileFormat;

final bool isPrivate;

/// Aufgrund der Security-Rules müssen die UIs in dem CloudFile-Dokument
/// stehen. Da für die Anhänge bereits array_contains in der Query
/// verwendet wird, kann nicht ein zweites array_contains benutzt
Expand All @@ -57,13 +59,15 @@ class CloudFile {
required this.sizeBytes,
required this.fileFormat,
required this.forUsers,
required this.isPrivate,
});

factory CloudFile.create({
required String id,
required String creatorID,
required String creatorName,
required String courseID,
bool isPrivate = false,
FolderPath path = FolderPath.root,
}) {
return CloudFile._(
Expand All @@ -82,6 +86,7 @@ class CloudFile {
sizeBytes: null,
fileFormat: FileFormat.unknown,
forUsers: {},
isPrivate: isPrivate,
);
}

Expand All @@ -108,6 +113,7 @@ class CloudFile {
// und somit direkt die Files-Dokumente geladen werden können (ohne auf die CF zu
// warten).
forUsers: {},
isPrivate: data['private'] ?? false,
);
}

Expand All @@ -129,6 +135,7 @@ class CloudFile {
'sizeBytes': sizeBytes,
'fileType': fileTypeEnumToString(fileFormat),
'forUsers': forUsers,
'private': isPrivate,
};
}

Expand All @@ -148,6 +155,7 @@ class CloudFile {
int? sizeBytes,
FileFormat? fileFormat,
Map<String, bool>? forUsers,
bool? isPrivate,
}) {
return CloudFile._(
id: id ?? this.id,
Expand All @@ -165,6 +173,7 @@ class CloudFile {
sizeBytes: sizeBytes ?? this.sizeBytes,
fileFormat: fileFormat ?? this.fileFormat,
forUsers: forUsers ?? this.forUsers,
isPrivate: isPrivate ?? this.isPrivate,
);
}

Expand Down
Loading