diff options
author | Stephan Schwär | 2020-11-11 02:04:26 +0100 |
---|---|---|
committer | Stephan Schwär | 2020-11-11 02:04:26 +0100 |
commit | f55401469bc6a8b44db3e831f18e645a9b429f22 (patch) | |
tree | 4ec9f01d7007bd4efb711efcaf66a21aeb2dadec | |
parent | Merge remote-tracking branch 'origin/feature/i18n' into feature-merge (diff) | |
parent | [client] fixed search funktion (diff) | |
download | tutor-module-f55401469bc6a8b44db3e831f18e645a9b429f22.tar.gz tutor-module-f55401469bc6a8b44db3e831f18e645a9b429f22.tar.xz tutor-module-f55401469bc6a8b44db3e831f18e645a9b429f22.zip |
Merge remote-tracking branch 'origin/buxfix/searchCaseSensitive' into feature-merge
8 files changed, 93 insertions, 18 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index 7e2fad8e..f65c650d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -444,6 +444,7 @@ public abstract class MainWindow { // Prevent switching to imageList when user is student if (!Session.canListImages()) { imagesItem.setEnabled(false); + homeItem.setEnabled(false); } JMenuItem lecturesItem = new JMenuItem(I18n.GUI.getString("MainWindow.MenuItem.lectures.text")); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java index 7de9459f..a758bbc0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java @@ -161,7 +161,7 @@ public class ImageListViewer extends QLabel { searchFieldPattern = null; } else { try { - searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE); + searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); txtSearch.setForeground(UIManager.getColor("TextField.foreground")); } catch (PatternSyntaxException ex) { txtSearch.setForeground(Color.RED); @@ -257,8 +257,11 @@ public class ImageListViewer extends QLabel { public ImageTable getImageTable() { return imageTable; } + public JComboBox getCboFilter() { + return cboFilter; + } - protected void setImageCountLabel(int i) { + protected void setImageCountLabel(final int i) { imageCountLabel.setText(Integer.toString(i)); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java index b2904280..9167565a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java @@ -277,7 +277,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa popupItemDownload.setEnabled(download); popupItemNewLecture.setEnabled(link); popupItemDelete.setEnabled(delete); - btnEditDetails.setEnabled(selCount == 1); + btnEditDetails.setEnabled(selCount == 1); btnShowPublishedImages.setEnabled(true); } @@ -419,7 +419,11 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa // we need to enable the "Show published images" button here, since we need to check // Session.getSatApiVersion() which is not set when this class is instantiated ctlImageListViewer.refreshList(false, 1); - btnShowPublishedImages.setVisible(Session.isImagePublishSupported()); + if(!Session.canListImages()) + { + btnShowPublishedImages.setVisible(false); + } else { + btnShowPublishedImages.setVisible(Session.isImagePublishSupported()); + } } - } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java index b89de75a..653a2586 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java @@ -156,7 +156,7 @@ public class LectureListWindow extends LectureListWindowLayout { searchFieldPattern = null; } else { try { - searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE); + searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); txtSearch.setForeground(UIManager.getColor("TextField.foreground")); } catch (PatternSyntaxException ex) { txtSearch.setForeground(Color.RED); @@ -364,10 +364,14 @@ public class LectureListWindow extends LectureListWindowLayout { btnEditLecture.setEnabled(Session.canListImages() && singleSelection); btnDeleteLecture.setEnabled(admin || !singleSelection); popupItemDelete.setEnabled(admin || !singleSelection); - popupItemLinked.setEnabled(Session.canListImages() && singleSelection); - popupItemDownload.setEnabled(Session.canListImages() && singleSelection); - popupItemNew.setEnabled(Session.canListImages() && singleSelection); + popupItemDelete.setVisible(admin || !singleSelection); + popupItemLinked.setEnabled(Session.canListImages()); + popupItemLinked.setVisible(Session.canListImages()); + popupItemDownload.setEnabled(singleSelection); + popupItemNew.setEnabled(Session.canListImages()); + popupItemNew.setVisible(Session.canListImages()); popupItemEdit.setEnabled(Session.canListImages() && singleSelection); + popupItemEdit.setVisible(Session.canListImages() && singleSelection); } /** @@ -474,6 +478,31 @@ public class LectureListWindow extends LectureListWindowLayout { btnNewLecture.setEnabled(Session.canListImages()); updateAvailableOptions(null); refreshList(false); + + if (!Session.canListImages()) + { + disableUnnecessaryButtonsForStudents(); + } + } + + /** + * This funtion disables all unnecessary buttons + * when Student is logged in. + */ + public void disableUnnecessaryButtonsForStudents() + { + btnDeleteLecture.setVisible(false); + btnEditLecture.setVisible(false); + btnNewLecture.setVisible(false); + btnSwitchView.setVisible(false); + + btnDeleteLecture.setEnabled(false); + btnEditLecture.setEnabled(false); + btnNewLecture.setEnabled(false); + btnSwitchView.setEnabled(false); + + cboFilter.setVisible(false); + cboFilter.setEnabled(false); } public void filterByImageBaseId(final String imageBaseId) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java index ef805799..32a9cd9e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java @@ -27,6 +27,7 @@ public class MainMenuWindow extends MainMenuWindowLayout { MainWindow.showPage(LectureListWindow.class); } }); + } @Override @@ -36,6 +37,12 @@ public class MainMenuWindow extends MainMenuWindowLayout { @Override public void requestShow() { + // here we need to check if the user is a student + // if so directly forward to lecturelist. + if(!Session.canListImages()) { + MainWindow.showPage(LectureListWindow.class); + } + btnShowVirtualMachines.setEnabled(Session.canListImages()); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java index aa43601e..46771d46 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java @@ -7,6 +7,7 @@ import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.LecturePermissions; +import org.openslx.bwlp.thrift.iface.Role; import org.openslx.bwlp.thrift.iface.SatelliteConfig; import org.openslx.bwlp.thrift.iface.WhoamiInfo; import org.openslx.sat.thrift.version.Feature; @@ -82,7 +83,7 @@ public class Session { return null; return data.user.userId; } - + /** * @return the organization id */ diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java index ca4c3e3c..99e90099 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java @@ -87,7 +87,21 @@ public class DbImage { public static ImageDetailsRead getImageDetails(UserInfo user, String imageBaseId) throws TNotFoundException, SQLException { try (MysqlConnection connection = Database.getConnection()) { - MysqlStatement stmt = connection.prepareStatement("SELECT i.imagebaseid, i.latestversionid," + + // if Student is trying to download only needed information is filled + MysqlStatement stmt = null; + if (user.role.equals("STUDENT")) + { + stmt = connection.prepareStatement("SELECT i.imagebaseid, i.latestversionid," + + " null, null, null, null, null, null, null, null," + + " null, null," + + " null, null, null, null," + + " null, null, null, null" + + " FROM imagebase i" + + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)" + + " WHERE i.imagebaseid = :imagebaseid"); + } else { + stmt = connection.prepareStatement("SELECT i.imagebaseid, i.latestversionid," + " i.displayname, i.description, i.osid, i.virtid, i.createtime, i.updatetime, i.ownerid, i.updaterid," + " i.sharemode, i.istemplate," + " i.canlinkdefault, i.candownloaddefault, i.caneditdefault, i.canadmindefault," @@ -95,6 +109,13 @@ public class DbImage { + " FROM imagebase i" + " LEFT JOIN imagepermission perm ON (i.imagebaseid = perm.imagebaseid AND perm.userid = :userid)" + " WHERE i.imagebaseid = :imagebaseid"); + } + + + + // if Student is trying to download only needed information is filled + + stmt.setString("userid", user == null ? "-" : user.userId); stmt.setString("imagebaseid", imageBaseId); ResultSet rs = stmt.executeQuery(); @@ -102,7 +123,7 @@ public class DbImage { throw new TNotFoundException(); // Exists: List<String> tags = DbSoftwareTag.getImageTags(connection, imageBaseId); - List<ImageVersionDetails> versions = getImageVersions(connection, imageBaseId); + List<ImageVersionDetails> versions = getImageVersions(connection, imageBaseId, user); ImagePermissions defaultPermissions = DbImagePermissions.fromResultSetDefault(rs); ImageDetailsRead image = new ImageDetailsRead(rs.getString("imagebaseid"), rs.getString("latestversionid"), versions, rs.getString("displayname"), @@ -247,13 +268,22 @@ public class DbImage { return resultSetToSummary(user, rs); } - protected static List<ImageVersionDetails> getImageVersions(MysqlConnection connection, String imageBaseId) + protected static List<ImageVersionDetails> getImageVersions(MysqlConnection connection, String imageBaseId, UserInfo user) throws SQLException { List<ImageVersionDetails> versionList = new ArrayList<>(); - MysqlStatement stmt = connection.prepareStatement("SELECT" - + " imageversionid, createtime, expiretime, filesize, uploaderid," - + " isrestricted, isvalid, isprocessed" + " FROM imageversion" - + " WHERE imagebaseid = :imagebaseid"); + MysqlStatement stmt = null; + if (user.role.equals("STUDENT")) { + stmt = connection.prepareStatement("SELECT" + + " imageversionid, createtime, expiretime, filesize, null," + + " isrestricted, isvalid, isprocessed" + " FROM imageversion" + + " WHERE imagebaseid = :imagebaseid"); + } else { + stmt = connection.prepareStatement("SELECT" + + " imageversionid, createtime, expiretime, filesize, uploaderid," + + " isrestricted, isvalid, isprocessed" + " FROM imageversion" + + " WHERE imagebaseid = :imagebaseid"); + + } stmt.setString("imagebaseid", imageBaseId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java index 06c1e5a7..4910ec4c 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java @@ -303,7 +303,7 @@ public class ServerHandler implements SatelliteServer.Iface { public ImageDetailsRead getImageDetails(String userToken, String imageBaseId) throws TAuthorizationException, TNotFoundException, TInvocationException { UserInfo user = SessionManager.getOrFail(userToken); - User.canSeeImageDetailsOrFail(user); + try { return DbImage.getImageDetails(user, imageBaseId); } catch (SQLException e) { |