Skip to content

Commit

Permalink
WIP (need to put params, front and test)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Mariotti committed Dec 10, 2024
1 parent b45887b commit 99aa6fd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,26 @@ public void getBoardResourceIds(HttpServerRequest request) {
});
}


@Get("/board/:boardId/notify")
@ApiDoc("Notify board shared users")
@ResourceFilter(ManageBoardRight.class)
@SecuredAction(value = "", type = ActionType.RESOURCE)
public void notifyBoardUsers(HttpServerRequest request) {
UserUtils.getUserInfos(eb, request, user -> {
String boardId = request.getParam(Field.BOARDID);
boardService.getBoardSharedUsers(boardId)
.onSuccess(usersIdsList -> {
JsonObject params = new JsonObject();
params.put(Field.BOARDURL, "/magneto#/board/view/")
.put(Field.BOARDNAME, );
timelineHelper.notifyTimeline(request, "magneto.notify_board", user, usersIdsList, params);
})
.onFailure(fail -> {
String message = String.format("[Magneto@%s::notifyBoardUsers] Failed to notify users of board : %s",
this.getClass().getSimpleName(), fail.getMessage());
log.error(message);
renderError(request);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,30 @@ public Future<List<Board>> getBoards(List<String> boardIds) {
return promise.future();
}

@Override
public Future<List<String>> getBoardSharedUsers(string boardId){
Promise<List<String>> promise = Promise.promise();
JsonObject query = this.getBoardById(boardId);
mongoDb.command(query.toString(), MongoDbResult.validResultHandler(either -> {
if (either.isLeft()) {
log.error("[Magneto@%s::getBoardSharedUsers] Failed to get all board shared users : %s", this.getClass().getSimpleName(),
either.left().getValue());
promise.fail(either.left().getValue());
} else {
JsonArray shared = either.right().getValue()
.getJsonArray(Field.SHARED, new JsonArray());

List<String> userIdsList = shared.stream()
.filter(JsonObject.class::isInstance)
.map(obj -> ((JsonObject) obj).getJsonObject("userId"))
.distinct()
.collect(Collectors.toList());
promise.complete();
}
}));
return promise.future();
}

@Override
public Future<JsonObject> getAllBoards(UserInfos user, Integer page,
String searchText, String folderId,
Expand Down Expand Up @@ -746,6 +770,16 @@ private JsonObject getBoardByIds(List<String> boardIds) {
return query.getAggregate();
}

private JsonObject getBoardById(String boardId) {
MongoQuery query = new MongoQuery(this.collection)
.match(new JsonObject()
.put(Field._ID, new JsonObject().put(Mongo.IN, new JsonArray().add(boardId))))
.project(new JsonObject()
.put(Field._ID, 1)
.put(Field.SHARED, 1));
return query.getAggregate();
}

@Override
public Future<List<Board>> getAllBoardsByCreationDate(StatisticsPayload statisticsPayload) {
Promise<List<Board>> promise = Promise.promise();
Expand Down
4 changes: 3 additions & 1 deletion backend/src/main/resources/i18n/timeline/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"timeline.magneto.shared.link.board": "board link",
"timeline.magneto.shared.link.folder": "folder link",
"magneto.share_board": "Sharing a board",
"magneto.share_folder": "Sharing a folder"
"magneto.share_folder": "Sharing a folder",
"timeline.magneto.notify": "Des modifications ont été apportées au tableau ",
"timeline.magneto.notify.consult": ". Consultez-le !"
}
9 changes: 9 additions & 0 deletions backend/src/main/resources/notify/notify_board.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<a>{{#i18n}}push.notif.magneto.share{{/i18n}}</a>
<br />
<span>
<span>
{{#i18n}}timeline.magneto.notify{{/i18n}}
<a href="{{boardUrl}}">{{boardName}}</a>
{{#i18n}}timeline.magneto.notify.consult{{/i18n}}
</span>
</span>
4 changes: 4 additions & 0 deletions backend/src/main/resources/notify/notify_board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"default-frequency": "IMMEDIATE",
"push-notif": true
}

0 comments on commit 99aa6fd

Please sign in to comment.