Skip to content

Commit

Permalink
Merge pull request #940 from WildMeOrg/785_improve_search_permission_…
Browse files Browse the repository at this point in the history
…logic

improve OpenSearch permission logic
  • Loading branch information
holmbergius authored Dec 18, 2024
2 parents ce5bc7f + fa16a54 commit e971846
Show file tree
Hide file tree
Showing 22 changed files with 492 additions and 92 deletions.
5 changes: 5 additions & 0 deletions config/indices.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
-- UGH, i guess _IDX (in caps!) should be what we standardize on. that is what datanucleus does.
-- to make matters worse, we have some places we named them explicitely in package.jdo (but those should fix themselves?)

BEGIN;

CREATE INDEX IF NOT EXISTS "MEDIAASSET_PARENTID_idx" ON "MEDIAASSET" ("PARENTID");
CREATE INDEX IF NOT EXISTS "MEDIAASSET_HASHCODE_idx" ON "MEDIAASSET" ("HASHCODE");

CREATE INDEX IF NOT EXISTS "ENCOUNTER_LOCATIONID_idx" ON "ENCOUNTER" ("LOCATIONID");
CREATE INDEX IF NOT EXISTS "ENCOUNTER_STATE_idx" ON "ENCOUNTER" ("STATE");
CREATE INDEX IF NOT EXISTS "ENCOUNTER_MODIFIED_idx" ON "ENCOUNTER" ("MODIFIED");
CREATE INDEX IF NOT EXISTS "ENCOUNTER_INDIVIDUALID_idx" ON "ENCOUNTER" ("INDIVIDUALID");
CREATE INDEX IF NOT EXISTS "ENCOUNTER_DATEINMILLISECONDS_idx" ON "ENCOUNTER" ("DATEINMILLISECONDS");
CREATE INDEX IF NOT EXISTS "ENCOUNTER_DECIMALLATITUDE_idx" ON "ENCOUNTER" ("DECIMALLATITUDE");
Expand Down Expand Up @@ -45,3 +48,5 @@ CREATE INDEX IF NOT EXISTS "TASK_CREATED_IDX" ON "TASK" ("CREATED");

INSERT INTO "RELATIONSHIP" ("RELATIONSHIP_ID", "MARKEDINDIVIDUALNAME1", "MARKEDINDIVIDUALNAME2", "MARKEDINDIVIDUALROLE1", "MARKEDINDIVIDUALROLE2", "TYPE", "STARTTIME", "ENDTIME") VALUES (0, (SELECT "INDIVIDUALID" FROM "MARKEDINDIVIDUAL" ORDER BY random() LIMIT 1), (SELECT "INDIVIDUALID" FROM "MARKEDINDIVIDUAL" ORDER BY random() LIMIT 1), 'placeholder', 'placeholder', 'placeholder-to-prevent-empty-table', 0, 0);

END;

27 changes: 25 additions & 2 deletions src/main/java/org/ecocean/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@
*/
public abstract void addComments(final String newComments);

public abstract List<String> userIdsWithViewAccess(Shepherd myShepherd);
public abstract List<String> userIdsWithEditAccess(Shepherd myShepherd);
// issue 785 makes this no longer necessary; the overrides are left on Occurrence and MarkedIndividual
// for now as reference -- but are not called. they will need to be addressed when these classes are searchable
// public abstract List<String> userIdsWithViewAccess(Shepherd myShepherd);
// public abstract List<String> userIdsWithEditAccess(Shepherd myShepherd);

public abstract String opensearchIndexName();

Expand All @@ -97,6 +99,8 @@ public JSONObject opensearchMapping() {
map.put("version", new org.json.JSONObject("{\"type\": \"long\"}"));
// id should be keyword for the sake of sorting
map.put("id", new org.json.JSONObject("{\"type\": \"keyword\"}"));
map.put("viewUsers", new org.json.JSONObject("{\"type\": \"keyword\"}"));
map.put("editUsers", new org.json.JSONObject("{\"type\": \"keyword\"}"));
return map;
}

Expand Down Expand Up @@ -153,11 +157,24 @@ public void opensearchUnindexDeep()
this.opensearchUnindex();
}

public void opensearchUpdate(final JSONObject updateData)
throws IOException {
if (updateData == null) return;
OpenSearch opensearch = new OpenSearch();

opensearch.indexUpdate(this.opensearchIndexName(), this.getId(), updateData);
}

// should be overridden
public void opensearchDocumentSerializer(JsonGenerator jgen, Shepherd myShepherd)
throws IOException, JsonProcessingException {
jgen.writeStringField("id", this.getId());
jgen.writeNumberField("version", this.getVersion());
jgen.writeNumberField("indexTimestamp", System.currentTimeMillis());

/*
these are no longer computed in the general opensearchIndex() call.
they are too expensive. see Encounter.opensearchIndexPermission()
jgen.writeFieldName("viewUsers");
jgen.writeStartArray();
Expand All @@ -172,6 +189,7 @@ public void opensearchDocumentSerializer(JsonGenerator jgen, Shepherd myShepherd
jgen.writeString(id);
}
jgen.writeEndArray();
*/
}

public void opensearchDocumentSerializer(JsonGenerator jgen)
Expand All @@ -196,6 +214,11 @@ public static JSONObject opensearchQuery(final String indexname, final JSONObjec
return res;
}

// this is so we can call it on Base obj, but really is only needed by [overridden by] Encounter (currently)
public boolean getOpensearchProcessPermissions() {
return false;
}

public static Map<String, Long> getAllVersions(Shepherd myShepherd, String sql) {
Query query = myShepherd.getPM().newQuery("javax.jdo.query.SQL", sql);
Map<String, Long> rtn = new HashMap<String, Long>();
Expand Down
Loading

0 comments on commit e971846

Please sign in to comment.