Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/EditQbQuestionController.java =================================================================== diff -u -r43b70960ce9b0bcf2d8a0d6e4ba5ec69c9fc3e6d -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_central/src/java/org/lamsfoundation/lams/web/qb/EditQbQuestionController.java (.../EditQbQuestionController.java) (revision 43b70960ce9b0bcf2d8a0d6e4ba5ec69c9fc3e6d) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/EditQbQuestionController.java (.../EditQbQuestionController.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -121,8 +121,9 @@ throw new RuntimeException("QbQuestion with uid:" + qbQuestionUid + " was not found!"); } Integer userId = getUserId(); - boolean editingAllowed = qbService.isQuestionInUserCollection(qbQuestion.getQuestionId(), userId) - || qbService.isQuestionInPublicCollection(qbQuestion.getQuestionId()); + boolean editingAllowed = qbService.isQuestionInPublicCollection(qbQuestion.getQuestionId()) + || qbService.isQuestionInUserOwnCollection(qbQuestion.getQuestionId(), userId) + || qbService.isQuestionInUserSharedCollection(qbQuestion.getQuestionId(), userId); if (!editingAllowed) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user does not have access to given QB question editing"); Index: lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java =================================================================== diff -u -r9012873415698350686bf05ac1ddb1ee5b8fe154 -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision 9012873415698350686bf05ac1ddb1ee5b8fe154) +++ lams_central/src/java/org/lamsfoundation/lams/web/qb/QbStatsController.java (.../QbStatsController.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -73,8 +73,9 @@ Integer userId = getUserId(); int qbQuestionId = stats.getQuestion().getQuestionId(); - boolean managementAllowed = qbService.isQuestionInUserCollection(qbQuestionId, userId) - || qbService.isQuestionInPublicCollection(qbQuestionId); + boolean managementAllowed = qbService.isQuestionInPublicCollection(qbQuestionId) + || qbService.isQuestionInUserOwnCollection(qbQuestionId, userId) + || qbService.isQuestionInUserSharedCollection(qbQuestionId, userId); model.addAttribute("managementAllowed", managementAllowed); Collection existingCollections = qbService.getQuestionCollectionsByUid(qbQuestionUid); Index: lams_common/src/java/org/lamsfoundation/lams/qb/QbUtils.java =================================================================== diff -u -rf0ff6bc30e8fa7e5d4201b7b9571194845ad3a83 -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_common/src/java/org/lamsfoundation/lams/qb/QbUtils.java (.../QbUtils.java) (revision f0ff6bc30e8fa7e5d4201b7b9571194845ad3a83) +++ lams_common/src/java/org/lamsfoundation/lams/qb/QbUtils.java (.../QbUtils.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -54,7 +54,7 @@ if (isRequestCameFromTool && !isDefaultQuestion && qbQuestionUid != null) { QbQuestion qbQuestion = qbService.getQuestionByUid(qbQuestionUid); - boolean isQuestionInUserCollection = qbService.isQuestionInUserCollection(qbQuestion.getQuestionId(), + boolean isQuestionInUserCollection = qbService.isQuestionInUserOwnCollection(qbQuestion.getQuestionId(), userId); if (!isQuestionInUserCollection) { // in a tool the user is editing a question which is not in one of his collections Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java =================================================================== diff -u -r03d284a4bdb2a2f2d6f57d0810e465f437c25155 -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java (.../IQbDAO.java) (revision 03d284a4bdb2a2f2d6f57d0810e465f437c25155) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/IQbDAO.java (.../IQbDAO.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -83,8 +83,10 @@ Set getCollectionQuestionIdsExcluded(long collectionUid, Collection qbQuestionIds); - boolean isQuestionInUserCollection(int userId, int qbQuestionId); + boolean isQuestionInUserOwnCollection(int userId, int qbQuestionId); + boolean isQuestionInUserSharedCollection(int userId, int qbQuestionId); + boolean isQuestionInPublicCollection(int qbQuestionId); int mergeQuestions(long sourceQbQUestionUid, long targetQbQuestionUid); Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java =================================================================== diff -u -r03d284a4bdb2a2f2d6f57d0810e465f437c25155 -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 03d284a4bdb2a2f2d6f57d0810e465f437c25155) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -109,10 +109,17 @@ private static final String FIND_QUESTIONS_BY_TOOL_CONTENT_ID = "SELECT tq.qbQuestion FROM QbToolQuestion AS tq " + "WHERE tq.toolContentId = :toolContentId"; - private static final String IS_QUESTION_IN_USER_COLLECTION = "SELECT DISTINCT 1 FROM lams_qb_collection_question AS cq " + private static final String IS_QUESTION_IN_USER_OWN_COLLECTION = "SELECT DISTINCT 1 FROM lams_qb_collection_question AS cq " + "JOIN lams_qb_collection AS c ON cq.collection_uid = c.uid AND " + "c.user_id = :userId AND cq.qb_question_id = :qbQuestionId"; + private static final String IS_QUESTION_IN_USER_SHARED_COLLECTION = "SELECT DISTINCT 1 FROM lams_qb_collection_question AS cq " + + "JOIN lams_qb_collection AS c ON cq.collection_uid = c.uid " + + "JOIN lams_qb_collection_organisation AS co ON co.collection_uid = c.uid " + + "JOIN lams_user_organisation AS uo USING (organisation_id) " + + "JOIN lams_user_organisation_role AS uor USING (user_organisation_id) " + + "WHERE uo.user_id = :userId AND cq.qb_question_id = :qbQuestionId AND uor.role_id = " + Role.ROLE_AUTHOR; + private static final String IS_QUESTION_IN_PUBLIC_COLLECTION = "SELECT DISTINCT 1 FROM lams_qb_collection_question AS cq " + "JOIN lams_qb_collection AS c ON cq.collection_uid = c.uid AND " + "c.user_id IS NULL AND cq.qb_question_id = :qbQuestionId"; @@ -494,12 +501,18 @@ } @Override - public boolean isQuestionInUserCollection(int userId, int qbQuestionId) { - return getSession().createNativeQuery(IS_QUESTION_IN_USER_COLLECTION).setParameter("userId", userId) + public boolean isQuestionInUserOwnCollection(int userId, int qbQuestionId) { + return getSession().createNativeQuery(IS_QUESTION_IN_USER_OWN_COLLECTION).setParameter("userId", userId) .setParameter("qbQuestionId", qbQuestionId).uniqueResult() != null; } @Override + public boolean isQuestionInUserSharedCollection(int userId, int qbQuestionId) { + return getSession().createNativeQuery(IS_QUESTION_IN_USER_SHARED_COLLECTION).setParameter("userId", userId) + .setParameter("qbQuestionId", qbQuestionId).uniqueResult() != null; + } + + @Override public boolean isQuestionInPublicCollection(int qbQuestionId) { return getSession().createNativeQuery(IS_QUESTION_IN_PUBLIC_COLLECTION) .setParameter("qbQuestionId", qbQuestionId).uniqueResult() != null; Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java =================================================================== diff -u -rd578cfde655760533b6ede422e7cf675a8c4ca6d -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision d578cfde655760533b6ede422e7cf675a8c4ca6d) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/IQbService.java (.../IQbService.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -150,8 +150,10 @@ void releaseFromCache(Object object); - boolean isQuestionInUserCollection(int qbQuestionId, int userId); + boolean isQuestionInUserOwnCollection(int qbQuestionId, int userId); + boolean isQuestionInUserSharedCollection(int qbQuestionId, int userId); + boolean isQuestionInPublicCollection(int qbQuestionId); void insertQuestion(QbQuestion qbQuestion); Index: lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java =================================================================== diff -u -r03d284a4bdb2a2f2d6f57d0810e465f437c25155 -rf1da04a71e4b26ddae139a92a1af522cbb087000 --- lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision 03d284a4bdb2a2f2d6f57d0810e465f437c25155) +++ lams_common/src/java/org/lamsfoundation/lams/qb/service/QbService.java (.../QbService.java) (revision f1da04a71e4b26ddae139a92a1af522cbb087000) @@ -378,10 +378,7 @@ @Override public List getUserOwnCollections(int userId) { - Map map = new HashMap<>(); - map.put("userId", userId); - map.put("personal", false); - List result = qbDAO.findByProperties(QbCollection.class, map); + List result = qbDAO.findByProperty(QbCollection.class, "userId", userId); Collections.sort(result, COLLECTION_NAME_COMPARATOR); return result; } @@ -631,9 +628,6 @@ public List getUserCollections(int userId) { Set collections = new LinkedHashSet<>(); - QbCollection privateCollection = getUserPrivateCollection(userId); - collections.add(privateCollection); - collections.addAll(getUserOwnCollections(userId)); QbCollection publicCollection = getPublicCollection(); @@ -668,11 +662,16 @@ } @Override - public boolean isQuestionInUserCollection(int qbQuestionId, int userId) { - return qbDAO.isQuestionInUserCollection(userId, qbQuestionId); + public boolean isQuestionInUserOwnCollection(int qbQuestionId, int userId) { + return qbDAO.isQuestionInUserOwnCollection(userId, qbQuestionId); } @Override + public boolean isQuestionInUserSharedCollection(int qbQuestionId, int userId) { + return qbDAO.isQuestionInUserSharedCollection(userId, qbQuestionId); + } + + @Override public boolean isQuestionInPublicCollection(int qbQuestionId) { return qbDAO.isQuestionInPublicCollection(qbQuestionId); }