🐛 Fix missing file permission creation
This commit is contained in:
@@ -163,6 +163,14 @@ public partial class PostService(
|
||||
post.Attachments = attachments
|
||||
.Select(id => post.Attachments.First(a => a.Id == id))
|
||||
.ToList();
|
||||
|
||||
if (post.Visibility == Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tags is not null)
|
||||
@@ -326,9 +334,25 @@ public partial class PostService(
|
||||
throw new InvalidOperationException("Categories contains one or more categories that wasn't exists.");
|
||||
}
|
||||
|
||||
var oldVisibility = post.Visibility;
|
||||
db.Update(post);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
if (post.Visibility == Shared.Models.PostVisibility.Public && oldVisibility != Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
else if (oldVisibility == Shared.Models.PostVisibility.Public && post.Visibility != Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.UnsetFilePublicAsync(new UnsetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
|
||||
// Process link preview in the background to avoid delaying post update
|
||||
_ = Task.Run(async () => await CreateLinkPreviewAsync(post));
|
||||
|
||||
|
||||
@@ -374,6 +374,8 @@ public class PublisherController(
|
||||
"Invalid picture id, unable to find the file on cloud."
|
||||
);
|
||||
picture = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.PictureId });
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
@@ -386,6 +388,8 @@ public class PublisherController(
|
||||
"Invalid background id, unable to find the file on cloud."
|
||||
);
|
||||
background = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.BackgroundId });
|
||||
}
|
||||
|
||||
var publisher = await ps.CreateIndividualPublisher(
|
||||
@@ -471,6 +475,8 @@ public class PublisherController(
|
||||
"Invalid picture id, unable to find the file on cloud."
|
||||
);
|
||||
picture = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.PictureId });
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
@@ -483,6 +489,8 @@ public class PublisherController(
|
||||
"Invalid background id, unable to find the file on cloud."
|
||||
);
|
||||
background = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.BackgroundId });
|
||||
}
|
||||
|
||||
var publisher = await ps.CreateOrganizationPublisher(
|
||||
@@ -569,6 +577,8 @@ public class PublisherController(
|
||||
var picture = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
publisher.Picture = picture;
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.PictureId });
|
||||
}
|
||||
|
||||
if (request.BackgroundId is not null)
|
||||
@@ -583,6 +593,8 @@ public class PublisherController(
|
||||
var background = SnCloudFileReferenceObject.FromProtoValue(queryResult);
|
||||
|
||||
publisher.Background = background;
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.BackgroundId });
|
||||
}
|
||||
|
||||
db.Update(publisher);
|
||||
|
||||
@@ -155,6 +155,8 @@ public class StickerController(
|
||||
return BadRequest("Icon not found.");
|
||||
|
||||
pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.IconId });
|
||||
}
|
||||
|
||||
db.StickerPacks.Add(pack);
|
||||
@@ -197,6 +199,8 @@ public class StickerController(
|
||||
return BadRequest("Icon not found.");
|
||||
|
||||
pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.IconId });
|
||||
}
|
||||
|
||||
db.StickerPacks.Update(pack);
|
||||
|
||||
Reference in New Issue
Block a user