Merge pull request #121 from onerain88/fix-file-acl

Fix file acl
oneRain 2021-04-21 11:18:12 +08:00 committed by GitHub
commit 338969ca15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -79,5 +79,27 @@ namespace Storage.Test {
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
[Test]
public async Task FileACL() {
LCUser user = await LCUser.LoginAnonymously();
LCFile file = new LCFile("avatar", AvatarFilePath);
LCACL acl = new LCACL();
acl.SetUserReadAccess(user, true);
file.ACL = acl;
await file.Save();
LCQuery<LCFile> query = LCFile.GetQuery();
LCFile avatar = await query.Get(file.ObjectId);
Assert.NotNull(avatar.ObjectId);
await LCUser.LoginAnonymously();
try {
LCFile forbiddenAvatar = await query.Get(file.ObjectId);
} catch (LCException e) {
Assert.AreEqual(e.Code, 403);
}
}
}
}

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using LeanCloud.Common;
using LeanCloud.Storage.Internal.File;
using LeanCloud.Storage.Internal.Object;
using LeanCloud.Storage.Internal.Codec;
namespace LeanCloud.Storage {
public class LCFile : LCObject {
@ -124,11 +125,13 @@ namespace LeanCloud.Storage {
async Task<Dictionary<string, object>> GetUploadToken() {
Dictionary<string, object> data = new Dictionary<string, object> {
{ "name", Name },
{ "key", Guid.NewGuid().ToString() },
{ "__type", "File" },
{ "mime_type", MimeType },
{ "metaData", MetaData }
};
if (ACL != null) {
data["ACL"] = LCEncoder.EncodeACL(ACL);
}
return await LCCore.HttpClient.Post<Dictionary<string, object>>("fileTokens", data: data);
}