Merge pull request #121 from onerain88/fix-file-acl
Fix file acl
commit
338969ca15
|
@ -79,5 +79,27 @@ namespace Storage.Test {
|
||||||
TestContext.WriteLine(file.ObjectId);
|
TestContext.WriteLine(file.ObjectId);
|
||||||
Assert.NotNull(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
||||||
using LeanCloud.Common;
|
using LeanCloud.Common;
|
||||||
using LeanCloud.Storage.Internal.File;
|
using LeanCloud.Storage.Internal.File;
|
||||||
using LeanCloud.Storage.Internal.Object;
|
using LeanCloud.Storage.Internal.Object;
|
||||||
|
using LeanCloud.Storage.Internal.Codec;
|
||||||
|
|
||||||
namespace LeanCloud.Storage {
|
namespace LeanCloud.Storage {
|
||||||
public class LCFile : LCObject {
|
public class LCFile : LCObject {
|
||||||
|
@ -124,11 +125,13 @@ namespace LeanCloud.Storage {
|
||||||
async Task<Dictionary<string, object>> GetUploadToken() {
|
async Task<Dictionary<string, object>> GetUploadToken() {
|
||||||
Dictionary<string, object> data = new Dictionary<string, object> {
|
Dictionary<string, object> data = new Dictionary<string, object> {
|
||||||
{ "name", Name },
|
{ "name", Name },
|
||||||
{ "key", Guid.NewGuid().ToString() },
|
|
||||||
{ "__type", "File" },
|
{ "__type", "File" },
|
||||||
{ "mime_type", MimeType },
|
{ "mime_type", MimeType },
|
||||||
{ "metaData", MetaData }
|
{ "metaData", MetaData }
|
||||||
};
|
};
|
||||||
|
if (ACL != null) {
|
||||||
|
data["ACL"] = LCEncoder.EncodeACL(ACL);
|
||||||
|
}
|
||||||
return await LCCore.HttpClient.Post<Dictionary<string, object>>("fileTokens", data: data);
|
return await LCCore.HttpClient.Post<Dictionary<string, object>>("fileTokens", data: data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue