Skip to content
Snippets Groups Projects
Commit c9406306 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Support 'ownerId' property for /room/find

parent 1a53e14f
Branches
No related merge requests found
......@@ -30,6 +30,7 @@ public interface RoomRepository extends CrudRepository<Room, String> {
List<Room> findInactiveGuestRoomsMetadata(long lastActivityBefore);
List<Room> findByOwner(ClientAuthentication owner, int start, int limit);
List<Room> findByOwnerId(String ownerId, int start, int limit);
List<String> findIdsByOwnerId(String ownerId);
List<Room> findAllForPublicPool();
List<Room> findForPublicPoolByOwner(ClientAuthentication owner);
List<Room> getRoomsWithStatsForOwner(ClientAuthentication owner, int start, int limit);
......
......@@ -287,6 +287,15 @@ public class CouchDbRoomRepository extends CouchDbCrudRepository<Room> implement
Room.class);
}
@Override
public List<String> findIdsByOwnerId(final String ownerId) {
ViewResult result = db.queryView(createQuery("by_ownerid")
.key(ownerId)
.includeDocs(false));
return result.getRows().stream().map(ViewResult.Row::getId).collect(Collectors.toList());
}
@Override
public List<Room> findAllForPublicPool() {
// TODO replace with new view
......
......@@ -47,8 +47,7 @@ public class RoomFindQueryService implements FindQueryService<Room> {
.map(UserProfile.RoomHistoryEntry::getRoomId).collect(Collectors.toList()));
}
if (findQuery.getProperties().getOwnerId() != null) {
/* TODO: nyi */
// ids.add(roomService.getUserRooms(findQuery.getProperties().getOwnerId()));
ids.add(roomService.getUserRoomIds(findQuery.getProperties().getOwnerId()));
}
return ids.stream().flatMap(list -> list.stream()).collect(Collectors.toSet());
......
......@@ -46,6 +46,8 @@ public interface RoomService extends EntityService<Room> {
List<Room> getUserRooms(String userId);
List<String> getUserRoomIds(String userId);
List<Room> getUserRoomHistory(String userId);
List<Room> getMyRooms(int offset, int limit);
......
......@@ -250,6 +250,13 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R
return roomRepository.findByOwnerId(userId, 0, 0);
}
/* TODO: Updated SpEL expression has not been tested yet */
@Override
@PreAuthorize("isAuthenticated() and hasPermission(#userId, 'userprofile', 'owner')")
public List<String> getUserRoomIds(String userId) {
return roomRepository.findIdsByOwnerId(userId);
}
@Override
@PreAuthorize("isAuthenticated()")
public List<Room> getMyRooms(final int offset, final int limit) {
......
......@@ -23,6 +23,13 @@ var designDoc = {
}
}
},
"by_ownerid": {
"map": function (doc) {
if (doc.type === "Room") {
emit(doc.ownerId, {_rev: doc._rev});
}
}
},
"by_lastactivity_for_guests": { /* needs rewrite */
"map": function (doc) {
if (doc.type === "Room" && !doc.poolProperties && doc.creator.indexOf("Guest") === 0) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment