Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User authentication for doc editing and creation on public layer. #864

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ public void performSubmittedWork(JSONObject submissionDoc, JSONObject currentDoc
}

JSONObject submittedDoc = submissionInfo.optJSONObject("submitted_doc");
String submitterName = submissionInfo.optString("submitter_name");
String docOwner = null;
if( null != submittedDoc ){
JSONObject nunaliitCreated = submittedDoc.optJSONObject("nunaliit_created");
if (null != nunaliitCreated) {
docOwner = nunaliitCreated.getString("name");
}
}
JSONArray nunaliitLayers = null;
if( null != submittedDoc ){
nunaliitLayers = submittedDoc.optJSONArray("nunaliit_layers");
Expand Down Expand Up @@ -281,6 +289,7 @@ public void performSubmittedWork(JSONObject submissionDoc, JSONObject currentDoc
if( !approved ){
boolean atLeastOneLayer = false;
boolean allLayerRoles = true;
boolean onPublicLayerAndIsDocOwner = false;

if( null != nunaliitLayers ){
for(int i=0;i<nunaliitLayers.length(); ++i){
Expand All @@ -289,9 +298,11 @@ public void performSubmittedWork(JSONObject submissionDoc, JSONObject currentDoc
if( "public".equals(layerId) ){
//atLeastOneLayer = true;
// Public layer, ignore
onPublicLayerAndIsDocOwner = isDocOwner(submitterName, docOwner);
} else if( layerId.startsWith("public_") ){
//atLeastOneLayer = true;
// Public layer, ignore
onPublicLayerAndIsDocOwner = isDocOwner(submitterName, docOwner);
} else {
atLeastOneLayer = true;

Expand All @@ -304,10 +315,10 @@ public void performSubmittedWork(JSONObject submissionDoc, JSONObject currentDoc
}
}
}

// If the document is on a controlled layer and the user
// has access to all those layers, the we can automatically approve
if( atLeastOneLayer && allLayerRoles ){
if( atLeastOneLayer && allLayerRoles || onPublicLayerAndIsDocOwner){
approved = true;
};
}
Expand Down Expand Up @@ -513,7 +524,13 @@ public void change(
this.notifyAll();
}
}

private boolean isDocOwner(String submitterName, String docOwner) {
boolean isOwner = false;
if ( null != submitterName && null != docOwner) {
isOwner = submitterName.equals(docOwner);
}
return isOwner;
}
private boolean rolesHaveAccessToLayerId(List<String> roles, String layerId){
boolean haveAccess = false;

Expand Down