mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 11:12:44 +00:00
api: handle sync v2 in SyncRequirement
This commit is contained in:
@@ -29,15 +29,15 @@ namespace Notesnook.API.Authorization
|
||||
{
|
||||
public class SyncRequirement : AuthorizationHandler<SyncRequirement>, IAuthorizationRequirement
|
||||
{
|
||||
private Dictionary<string, string> pathErrorPhraseMap = new Dictionary<string, string>
|
||||
private readonly Dictionary<string, string> pathErrorPhraseMap = new Dictionary<string, string>
|
||||
{
|
||||
["/sync/attachments"] = "use attachments",
|
||||
["/sync"] = "sync your notes",
|
||||
["/hubs/sync"] = "sync your notes",
|
||||
["/hubs/sync/v2"] = "sync your notes",
|
||||
["/monographs"] = "publish monographs"
|
||||
};
|
||||
|
||||
private string[] allowedClaims = { "trial", "premium", "premium_canceled" };
|
||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, SyncRequirement requirement)
|
||||
{
|
||||
PathString path = context.Resource is DefaultHttpContext httpContext ? httpContext.Request.Path : null;
|
||||
@@ -45,7 +45,7 @@ namespace Notesnook.API.Authorization
|
||||
if (result.Succeeded) context.Succeed(requirement);
|
||||
else
|
||||
{
|
||||
var hasReason = result.AuthorizationFailure.FailureReasons.Count() > 0;
|
||||
var hasReason = result.AuthorizationFailure.FailureReasons.Any();
|
||||
if (hasReason)
|
||||
context.Fail(result.AuthorizationFailure.FailureReasons.First());
|
||||
else context.Fail();
|
||||
@@ -60,7 +60,7 @@ namespace Notesnook.API.Authorization
|
||||
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
var reason = new AuthorizationFailureReason[]
|
||||
var reason = new[]
|
||||
{
|
||||
new AuthorizationFailureReason(this, "Invalid token.")
|
||||
};
|
||||
@@ -84,7 +84,7 @@ namespace Notesnook.API.Authorization
|
||||
}
|
||||
|
||||
var error = $"Please confirm your email to {phrase}.";
|
||||
var reason = new AuthorizationFailureReason[]
|
||||
var reason = new[]
|
||||
{
|
||||
new AuthorizationFailureReason(this, error)
|
||||
};
|
||||
@@ -92,7 +92,6 @@ namespace Notesnook.API.Authorization
|
||||
// context.Fail(new AuthorizationFailureReason(this, error));
|
||||
}
|
||||
|
||||
var isProOrTrial = User.HasClaim((c) => c.Type == "notesnook:status" && allowedClaims.Contains(c.Value));
|
||||
if (hasSyncScope && isInAudience && hasRole && isEmailVerified)
|
||||
return PolicyAuthorizationResult.Success(); //(requirement);
|
||||
return PolicyAuthorizationResult.Forbid();
|
||||
|
||||
Reference in New Issue
Block a user