Skip to content

Commit

Permalink
Feature/#8812 anon access fix (#8815)
Browse files Browse the repository at this point in the history
* #8812 resolve issue with anonymous access

* #8812 bug fix with anonymous access
  • Loading branch information
webplusai authored Dec 14, 2024
1 parent ae5bd9d commit 67232aa
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.middleware = function (request, response, state, entityType, permissionN
var decodedEntityName = decodeURIComponent(partiallyDecoded);
var aclRecord = sqlTiddlerDatabase.getACLByName(entityType, decodedEntityName);
var isGetRequest = request.method === "GET";
var hasAnonymousAccess = state.allowAnon && (isGetRequest ? state.allowAnonReads : state.allowAnonWrites);
var hasAnonymousAccess = state.allowAnon ? (isGetRequest ? state.allowAnonReads : state.allowAnonWrites) : false;
var entity = sqlTiddlerDatabase.getEntityByName(entityType, decodedEntityName);
if(entity?.owner_id) {
if(state.authenticatedUser?.user_id && (state.authenticatedUser?.user_id !== entity.owner_id) || !state.authenticatedUser?.user_id && !hasAnonymousAccess) {
Expand All @@ -59,7 +59,7 @@ exports.middleware = function (request, response, state, entityType, permissionN
}
} else {
// First, we need to check if anonymous access is allowed
if(!state.authenticatedUser?.user_id && !hasAnonymousAccess && (isGetRequest && entity?.owner_id)) {
if(!state.authenticatedUser?.user_id && !hasAnonymousAccess) {
if(!response.headersSent) {
response.writeHead(401, "Unauthorized");
response.end();
Expand Down

0 comments on commit 67232aa

Please sign in to comment.