Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Feature/moderate requests (#166)
Browse files Browse the repository at this point in the history
* Update removing restrictions on queries shown to moderator user;
ModeratorQueriesDetailBean the access restriction for queries is removed;
DBUtil adjusted SQL to return all queries for the moderator user;

* Added menu entry for admin users to get to moderator page.

* Added moderator xhtml pages and flag in UserBean to identify moderator;
CommentBean needs still to be updated to show moderator in display

* Database - table "comment - added column moderated of type boolean;
this requires a regeneration of the affected POJOs using JOOQ;

* UserBean - added checks if user has Moderator Role;
UserBean - added variable to hold if user is on moderator details page (looks like the easiest way to keep this here, still ugly);
navbar.xhtml - bugfix, did not point to moderator sub section;
comment.xhtml - this is included in all details pages to render comments, now includes the prefix "Moderated by:" if the flag is set in the table comment on column moderated to true;
jooq/tables - regenerated using JOOQ generate

* rebased onto master
detail.xhtml - removed unused reference to ModeratorQueriesDetailBean:
DbUtil.java - set Moderated Flag on Comments when loaded from database;
DBUtil.java - set moderated flag when a new comment is created, this should only be set to true if the comment is created by a Moderator user in the moderator pages;
CommentBean.java - set moderated flag when the comment is created, only set if the user is doing this on the moderator pages and has the moderator role;
ResearcherQueriesBean.java - ensure moderator mode is deactivated for the user, we can not make sure the user bean set this correctly to false;
OwnerQueriesBean.java - ensure moderator mode is deactivated for the user, we can not make sure the user bean set this correctly to false;
ModeratorQueriesBean.java - new Bean copied from OwnerQueriesBean.java, with find/replace; (ugly...)
ModeratorQueriesDetailBean.java - new Bean copied from OwnerQueriesDetailBean.java, with find/replace; (ugly...)
AdminDebugBean.java - add the flag for moderator when a query is transferred in the comment;

* global.properties - removed excess colon for moderator pagetitle
comment.xhtml - add icon (glyphicon-alert) to mark moderated comments

* ReviewBean.java - deactivation of ModeratorMode (just for safety)
NetworkBean.java - deactivation of ModeratorMode (just for safety)

* ModeratorQueriesBean - switched to use dedicated query
DBUtil - added dedicated method for moderator queries

* removed collection dropdown for moderators

* fixed wrong method call

* new table moderators_network

* new table moderators_network

* Moderators network connection

* refactoring

* added moderated column on table offer because comment.xhtml is used in request-wide chat and 1:1 chat, leading to an exception in 1:1 chat when there is no moderated column on the table offer.

* removed ModeratorNetwork
added flag is_moderator on table person
changed V22 sql to add moderated columns to offer and comment
bugfix in comment.xhtml to display icon and "moderated by" for moderated comments and offers

Co-authored-by: RadovanTomik <tomasik@mail.muni.cz>
  • Loading branch information
konradlang and RadovanTomik authored Dec 22, 2022
1 parent 6b07a5b commit e76b52a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class ModeratorQueriesDetailBean implements Serializable {
private static final long serialVersionUID = 1L;

private static final Logger logger = LogManager.getLogger(ModeratorQueriesDetailBean.class);
private String LOGGING_PREFIX = "97776fdc5f92-OwnerQueriesDetailBean ";
private String LOGGING_PREFIX = "eaa457575042-ModeratorQueriesDetailBean ";

@ManagedProperty(value = "#{userBean}")
private UserBean userBean;
Expand Down Expand Up @@ -315,7 +315,9 @@ public String initialize() {
Person queryAuthor = DbUtil.getPersonDetails(config, query.getResearcherId());
addme.setQueryAuthor(queryAuthor);
queries.add(0, addme);
/* no return here, need to get the requestLifeCycleStatus
return null;
*/
}
}

Expand Down
36 changes: 25 additions & 11 deletions src/main/java/de/samply/bbmri/negotiator/db/util/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,9 @@ public static List<OwnerQueryStatsDTO> getOwnerQueries(Config config, int userId
public static List<OwnerQueryStatsDTO> getModeratorQueriesAtOffset(Config config, int userId, Set<String> filters, Flag flag, Boolean isTestRequest, int offset, int size) {
Person queryAuthor = Tables.PERSON.as("query_author");

Condition condition = Tables.PERSON_COLLECTION.PERSON_ID.eq(userId);
// replaced PERSON_COLLECTION with PERSON as we are not restricting on assigned collections for moderators
// Condition condition = Tables.PERSON_COLLECTION.PERSON_ID.eq(userId);
Condition condition = Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull();

if(filters != null && filters.size() > 0) {
Condition titleCondition = DSL.trueCondition();
Expand All @@ -875,7 +877,8 @@ public static List<OwnerQueryStatsDTO> getModeratorQueriesAtOffset(Config config
condition = condition.and(Tables.FLAGGED_QUERY.FLAG.ne(Flag.IGNORED).or(Tables.FLAGGED_QUERY.FLAG.isNull()));
}

condition = condition.and(Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull());
// already first condition:
// condition = condition.and(Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull());

Table<RequestStatusRecord> requestStatusTableStart = Tables.REQUEST_STATUS.as("request_status_table_start");
Table<RequestStatusRecord> requestStatusTableAbandon = Tables.REQUEST_STATUS.as("request_status_table_abandon");
Expand All @@ -889,7 +892,8 @@ public static List<OwnerQueryStatsDTO> getModeratorQueriesAtOffset(Config config
.select(DSL.decode().when(Tables.FLAGGED_QUERY.FLAG.isNull(), Flag.UNFLAGGED)
.otherwise(Tables.FLAGGED_QUERY.FLAG).as("flag"))
.from(Tables.QUERY)

/* show all queries to the Moderator user
TODO: add system to ensure moderator only has queries from his network or other criteria shown
.join(Tables.QUERY_COLLECTION, JoinType.JOIN)
.on(Tables.QUERY.ID.eq(Tables.QUERY_COLLECTION.QUERY_ID))
Expand All @@ -901,16 +905,19 @@ public static List<OwnerQueryStatsDTO> getModeratorQueriesAtOffset(Config config
.join(Tables.NETWORK_COLLECTION_LINK, JoinType.LEFT_OUTER_JOIN)
.on(Tables.NETWORK_COLLECTION_LINK.COLLECTION_ID.eq(Tables.COLLECTION.ID))

*/
.join(queryAuthor, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.RESEARCHER_ID.eq(queryAuthor.ID))

.join(Tables.COMMENT, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.ID.eq(Tables.COMMENT.QUERY_ID).and(Tables.COMMENT.STATUS.eq("published")))

.join(Tables.FLAGGED_QUERY, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.ID.eq(Tables.FLAGGED_QUERY.QUERY_ID))
/*
.join(Tables.FLAGGED_QUERY, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.ID.eq(Tables.FLAGGED_QUERY.QUERY_ID).and(Tables.FLAGGED_QUERY.PERSON_ID.eq(Tables.PERSON_COLLECTION.PERSON_ID)))

*/
.join(requestStatusTableStart, JoinType.JOIN)
.on(Tables.QUERY.ID.eq(requestStatusTableStart.field(Tables.REQUEST_STATUS.QUERY_ID))
.and(requestStatusTableStart.field(Tables.REQUEST_STATUS.STATUS).eq("started")))
Expand All @@ -921,7 +928,7 @@ public static List<OwnerQueryStatsDTO> getModeratorQueriesAtOffset(Config config

.join(Tables.PERSON_COMMENT, JoinType.LEFT_OUTER_JOIN)
.on(Tables.PERSON_COMMENT.COMMENT_ID.eq(Tables.COMMENT.ID)
.and(Tables.PERSON_COMMENT.PERSON_ID.eq(Tables.PERSON_COLLECTION.PERSON_ID))
// .and(Tables.PERSON_COMMENT.PERSON_ID.eq(Tables.PERSON_COLLECTION.PERSON_ID))
.and(Tables.PERSON_COMMENT.READ.eq(false)))

.where(condition).and(requestStatusTableAbandon.field(Tables.REQUEST_STATUS.STATUS).isNull())
Expand Down Expand Up @@ -1122,7 +1129,9 @@ public static int countOwnerQueries(Config config, int userId, Set<String> filte
public static int countModeratorQueries(Config config, int userId, Set<String> filters, Flag flag) {
Person queryAuthor = Tables.PERSON.as("query_author");

Condition condition = Tables.PERSON_COLLECTION.PERSON_ID.eq(userId);
// replaced PERSON_COLLECTION with PERSON as we are not restricting on assigned collections for moderators
// Condition condition = Tables.PERSON_COLLECTION.PERSON_ID.eq(userId);
Condition condition = Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull();

if(filters != null && filters.size() > 0) {
Condition titleCondition = DSL.trueCondition();
Expand All @@ -1147,7 +1156,8 @@ public static int countModeratorQueries(Config config, int userId, Set<String> f
}


condition = condition.and(Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull());
// already first condition:
//condition = condition.and(Tables.QUERY.NEGOTIATION_STARTED_TIME.isNotNull());

Table<RequestStatusRecord> requestStatusTableStart = Tables.REQUEST_STATUS.as("request_status_table_start");
Table<RequestStatusRecord> requestStatusTableAbandon = Tables.REQUEST_STATUS.as("request_status_table_abandon");
Expand All @@ -1158,7 +1168,8 @@ public static int countModeratorQueries(Config config, int userId, Set<String> f
.select(DSL.decode().when(Tables.FLAGGED_QUERY.FLAG.isNull(), Flag.UNFLAGGED)
.otherwise(Tables.FLAGGED_QUERY.FLAG).as("flag"))
.from(Tables.QUERY)

/* show all queries to the Moderator user
TODO: add system to ensure moderator only has queries from his network or other criteria shown
.join(Tables.QUERY_COLLECTION, JoinType.JOIN)
.on(Tables.QUERY.ID.eq(Tables.QUERY_COLLECTION.QUERY_ID))
Expand All @@ -1170,13 +1181,16 @@ public static int countModeratorQueries(Config config, int userId, Set<String> f
.join(Tables.NETWORK_COLLECTION_LINK, JoinType.LEFT_OUTER_JOIN)
.on(Tables.NETWORK_COLLECTION_LINK.COLLECTION_ID.eq(Tables.COLLECTION.ID))

*/
.join(queryAuthor, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.RESEARCHER_ID.eq(queryAuthor.ID))

.join(Tables.FLAGGED_QUERY, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.ID.eq(Tables.FLAGGED_QUERY.QUERY_ID))
/*
.join(Tables.FLAGGED_QUERY, JoinType.LEFT_OUTER_JOIN)
.on(Tables.QUERY.ID.eq(Tables.FLAGGED_QUERY.QUERY_ID).and(Tables.FLAGGED_QUERY.PERSON_ID.eq(Tables.PERSON_COLLECTION.PERSON_ID)))

*/
.join(requestStatusTableStart, JoinType.JOIN)
.on(Tables.QUERY.ID.eq(requestStatusTableStart.field(Tables.REQUEST_STATUS.QUERY_ID))
.and(requestStatusTableStart.field(Tables.REQUEST_STATUS.STATUS).eq("started")))
Expand Down

0 comments on commit e76b52a

Please sign in to comment.