SEBSERV-184 fixes and migration script

This commit is contained in:
anhefti 2021-06-23 15:57:46 +02:00
parent d2036a8598
commit bb1713da3c
10 changed files with 213 additions and 22 deletions

View file

@ -182,6 +182,7 @@ public class ConfigTemplateAttributeForm implements TemplateComposer {
valueContext,
configuration,
new View(-1L, "template", 10, 0, templateId),
viewName -> null,
attributeMapping,
1, false, null);

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.content;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT;
@ -157,11 +158,17 @@ public class SEBSettingsForm implements TemplateComposer {
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
final List<ViewContext> viewContexts = new ArrayList<>();
final Function<String, ViewContext> viewContextSupplier = viewName -> viewContexts
.stream()
.filter(v -> viewName.equals(v.getName()))
.findFirst()
.orElse(null);
for (final View view : views) {
final ViewContext viewContext = this.examConfigurationService.createViewContext(
pageContext,
configuration,
view,
viewContextSupplier,
attributes,
20,
readonly,

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.service.examconfig;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.widgets.Composite;
@ -74,6 +75,7 @@ public interface ExamConfigurationService {
* @param pageContext The original PageContext that holds the state of the overall page.
* @param configuration The configuration on which the exam configuration property page is based on.
* @param view The View of the context
* @param viewContextSupplier ViewContext supplier to get context by view name
* @param attributeMapping The attribute mapping if the properties page
* @param rows Number of rows supported for the view.
* @param readonly Indicates if the view shall be composed in read-only mode.
@ -82,6 +84,7 @@ public interface ExamConfigurationService {
PageContext pageContext,
Configuration configuration,
View view,
Function<String, ViewContext> viewContextSupplier,
AttributeMapping attributeMapping,
int rows,
boolean readonly,

View file

@ -13,6 +13,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.tomcat.util.buf.StringUtils;
@ -174,6 +175,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
final PageContext pageContext,
final Configuration configuration,
final View view,
final Function<String, ViewContext> viewContextSupplier,
final AttributeMapping attributeMapping,
final int rows,
final boolean readonly,
@ -182,6 +184,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
return new ViewContext(
configuration,
view,
viewContextSupplier,
rows,
attributeMapping,
new ValueChangeListenerImpl(

View file

@ -12,6 +12,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,6 +32,7 @@ public final class ViewContext {
private final Configuration configuration;
private final View view;
private final Function<String, ViewContext> viewContextSupplier;
private final int rows;
final AttributeMapping attributeMapping;
@ -42,6 +44,7 @@ public final class ViewContext {
ViewContext(
final Configuration configuration,
final View view,
final Function<String, ViewContext> viewContextSupplier,
final int rows,
final AttributeMapping attributeContext,
final ValueChangeListener valueChangeListener,
@ -55,6 +58,7 @@ public final class ViewContext {
this.configuration = configuration;
this.view = view;
this.viewContextSupplier = viewContextSupplier;
this.rows = rows;
this.attributeMapping = attributeContext;
@ -145,11 +149,18 @@ public final class ViewContext {
}
public void disable(final String attributeName) {
disable(this.getAttributeIdByName(attributeName));
disable(this, this.getAttributeIdByName(attributeName));
}
public void disable(final Long attributeId) {
final InputField inputField = this.inputFieldMapping.get(attributeId);
public void disable(final String viewName, final String attributeName) {
final ViewContext viewContext = this.viewContextSupplier.apply(viewName);
if (viewContext != null) {
disable(viewContext, viewContext.getAttributeIdByName(attributeName));
}
}
public void disable(final ViewContext context, final Long attributeId) {
final InputField inputField = context.inputFieldMapping.get(attributeId);
if (inputField == null) {
return;
}
@ -158,11 +169,18 @@ public final class ViewContext {
}
public void enable(final String attributeName) {
enable(this.getAttributeIdByName(attributeName));
enable(this, this.getAttributeIdByName(attributeName));
}
public void enable(final Long attributeId) {
final InputField inputField = this.inputFieldMapping.get(attributeId);
public void enable(final String viewName, final String attributeName) {
final ViewContext viewContext = this.viewContextSupplier.apply(viewName);
if (viewContext != null) {
enable(viewContext, viewContext.getAttributeIdByName(attributeName));
}
}
public void enable(final ViewContext context, final Long attributeId) {
final InputField inputField = context.inputFieldMapping.get(attributeId);
if (inputField == null) {
return;
}
@ -171,11 +189,18 @@ public final class ViewContext {
}
public void disableGroup(final String attributeName) {
disableGroup(this.getAttributeIdByName(attributeName));
disableGroup(this, this.getAttributeIdByName(attributeName));
}
public void disableGroup(final Long attributeId) {
final InputField inputField = this.inputFieldMapping.get(attributeId);
public void disableGroup(final String viewName, final String attributeName) {
final ViewContext viewContext = this.viewContextSupplier.apply(viewName);
if (viewContext != null) {
disableGroup(viewContext, viewContext.getAttributeIdByName(attributeName));
}
}
public void disableGroup(final ViewContext context, final Long attributeId) {
final InputField inputField = context.inputFieldMapping.get(attributeId);
if (inputField == null) {
return;
}
@ -183,11 +208,11 @@ public final class ViewContext {
inputField.disable(true);
try {
this.attributeMapping.attributeGroupMapping
context.attributeMapping.attributeGroupMapping
.get(inputField.getOrientation().groupId)
.stream()
.map(ConfigurationAttribute::getId)
.map(this.inputFieldMapping::get)
.map(context.inputFieldMapping::get)
.forEach(InputField::setDefaultValue);
} catch (final Exception e) {
log.warn("Failed to send attribute value update to server: ", e);
@ -195,11 +220,18 @@ public final class ViewContext {
}
public void enableGroup(final String attributeName) {
enableGroup(this.getAttributeIdByName(attributeName));
enableGroup(this, this.getAttributeIdByName(attributeName));
}
public void enableGroup(final Long attributeId) {
final InputField inputField = this.inputFieldMapping.get(attributeId);
public void enableGroup(final String viewName, final String attributeName) {
final ViewContext viewContext = this.viewContextSupplier.apply(viewName);
if (viewContext != null) {
enableGroup(viewContext, viewContext.getAttributeIdByName(attributeName));
}
}
public void enableGroup(final ViewContext context, final Long attributeId) {
final InputField inputField = context.inputFieldMapping.get(attributeId);
if (inputField == null) {
return;
}

View file

@ -21,9 +21,12 @@ import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext;
@Lazy
@Service
@GuiProfile
public class HideToolbarDefaultRule implements ValueChangeRule {
public class BrowserWindowToolbarRule implements ValueChangeRule {
public static final String KEY_ENABLE_TOOLBAR = "enableBrowserWindowToolbar";
public static final String KEY_ADDBAR_MAIN = "browserWindowAllowAddressBar";
public static final String KEY_ADDBAR = "newBrowserWindowAllowAddressBar";
public static final String KEY_DEV_CON = "allowDeveloperConsole";
public static final String KEY_HIDE_TOOLBAR = "hideBrowserWindowToolbar";
@Override
@ -38,8 +41,14 @@ public class HideToolbarDefaultRule implements ValueChangeRule {
final ConfigurationValue value) {
if (BooleanUtils.toBoolean(value.value)) {
context.enable(KEY_ADDBAR_MAIN);
context.enable(KEY_ADDBAR);
context.enable(KEY_DEV_CON);
context.enable(KEY_HIDE_TOOLBAR);
} else {
context.disable(KEY_ADDBAR_MAIN);
context.disable(KEY_ADDBAR);
context.disable(KEY_DEV_CON);
context.disable(KEY_HIDE_TOOLBAR);
}
}

View file

@ -29,6 +29,8 @@ public class IgnoreSEBService implements ValueChangeRule {
public static final String KEY_ATTR_1 = "enableWindowsUpdate";
public static final String KEY_ATTR_2 = "enableChromeNotifications";
public static final String KEY_ATTR_3 = "allowScreenSharing";
public static final String KEY_REG = "registry";
public static final String KEY_REG_RUNNING_SEB = "insideSebEnableSwitchUser";
@Override
public boolean observesAttribute(final ConfigurationAttribute attribute) {
@ -51,6 +53,7 @@ public class IgnoreSEBService implements ValueChangeRule {
context.disable(KEY_ATTR_1);
context.disable(KEY_ATTR_2);
context.disable(KEY_ATTR_3);
context.disableGroup(KEY_REG, KEY_REG_RUNNING_SEB);
context.setValue(
KEY_SEB_SERVICE_POLICY,
@ -69,6 +72,7 @@ public class IgnoreSEBService implements ValueChangeRule {
context.enable(KEY_ATTR_1);
context.enable(KEY_ATTR_2);
context.enable(KEY_ATTR_3);
context.enableGroup(KEY_REG, KEY_REG_RUNNING_SEB);
}
}

View file

@ -0,0 +1,111 @@
-- -----------------------------------------------------
-- Add missing (new) SEB settings attributes
-- -----------------------------------------------------
INSERT IGNORE INTO configuration_attribute VALUES
(950, 'showSideMenu', 'CHECKBOX', null, null, null, null, 'true'),
(951, 'browserWindowAllowAddressBar', 'CHECKBOX', null, null, null, null, 'false'),
(952, 'newBrowserWindowAllowAddressBar', 'CHECKBOX', null, null, null, null, 'false'),
(953, 'allowDeveloperConsole', 'CHECKBOX', null, null, null, null, 'false'),
(960, 'allowFind', 'CHECKBOX', null, null, null, null, 'true'),
(961, 'allowPDFReaderToolbar', 'CHECKBOX', null, null, null, null, 'false'),
(970, 'setVmwareConfiguration', 'CHECKBOX', null, null, null, null, 'false')
;
-- -----------------------------------------------------
-- Correct default value for newBrowserWindowShowURL
-- -----------------------------------------------------
UPDATE configuration_attribute SET default_value='2' WHERE id=928;
-- -----------------------------------------------------
-- Remove unused orientations
-- -----------------------------------------------------
-- remove enableTouchExit setting from GUI
DELETE FROM `orientation` WHERE `config_attribute_id`=9;
-- remove taskBarHeight from GUI
DELETE FROM `orientation` WHERE `config_attribute_id`=17;
-- remove Browser security
DELETE FROM `orientation` WHERE `config_attribute_id`=36;
DELETE FROM `orientation` WHERE `config_attribute_id`=37;
DELETE FROM `orientation` WHERE `config_attribute_id`=38;
DELETE FROM `orientation` WHERE `config_attribute_id`=39;
DELETE FROM `orientation` WHERE `config_attribute_id`=40;
DELETE FROM `orientation` WHERE `config_attribute_id`=41;
DELETE FROM `orientation` WHERE `config_attribute_id`=49;
-- -----------------------------------------------------
-- Add new orientations
-- -----------------------------------------------------
-- insert Browser window toolbar
INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES
(951, 0, 2, 'wintoolbar', 0, 7, 5, 1, 'NONE'),
(952, 0, 2, 'wintoolbar', 0, 8, 5, 1, 'NONE'),
(953, 0, 2, 'wintoolbar', 0, 9, 5, 1, 'NONE')
;
-- insert Taskbar / Dock
INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES
(950, 0, 2, 'taskbar', 0, 10, 3, 1, 'NONE');
-- insert Browser security
INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES
(960, 0, 3, 'browserSecurity', 0, 5, 7, 1, 'NONE'),
(961, 0, 3, 'browserSecurity', 0, 6, 7, 1, 'NONE')
;
-- insert Restrictions in Exam Window
INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES
(919, 0, 3, 'examWindow', 2, 12, 5, 1, 'LEFT_SPAN'),
(928, 0, 3, 'additionalWindow', 2, 15, 5, 1, 'LEFT_SPAN');
-- insert Set VMWare Configuration
INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES
(970, 0, 10, 'registry', 0, 7, 4, 1, 'NONE');
-- -----------------------------------------------------
-- Update old orientations
-- -----------------------------------------------------
-- update stretch the orientation for Browser view mode group
UPDATE orientation SET width=7 WHERE config_attribute_id=8;
-- update Browser window toolbar
UPDATE orientation SET width=4 WHERE config_attribute_id=13;
UPDATE orientation SET x_position=0, y_position=10, width=5 WHERE config_attribute_id=14;
UPDATE orientation SET x_position=4, y_position=6, width=3 WHERE config_attribute_id=15;
-- update Taskbar / Dock
UPDATE orientation SET x_position=4, y_position=9, width=3 WHERE config_attribute_id=812;
UPDATE orientation SET x_position=4, y_position=10, width=3 WHERE config_attribute_id=18;
UPDATE orientation SET x_position=4, y_position=11, width=3 WHERE config_attribute_id=19;
UPDATE orientation SET x_position=4, y_position=12, width=3 WHERE config_attribute_id=20;
-- update zoom and zoom mode
UPDATE orientation SET width=4 WHERE config_attribute_id=21;
UPDATE orientation SET x_position=4, width=3 WHERE config_attribute_id=23;
-- update Browser security
UPDATE orientation SET y_position=7, width=7 WHERE config_attribute_id=48;
-- update Restrictions in Exam Window
UPDATE orientation SET group_id='examWindow', y_position=9, width=7 WHERE config_attribute_id=42;
UPDATE orientation SET group_id='examWindow', y_position=10, width=7 WHERE config_attribute_id=44;
UPDATE orientation SET group_id='examWindow', y_position=11, width=7 WHERE config_attribute_id=46;
-- update Restrictions in Additional Window
UPDATE orientation SET group_id='additionalWindow', x_position=0, y_position=12, width=7 WHERE config_attribute_id=43;
UPDATE orientation SET group_id='additionalWindow', x_position=0, y_position=13, width=7 WHERE config_attribute_id=45;
UPDATE orientation SET group_id='additionalWindow', x_position=0, y_position=14, width=7 WHERE config_attribute_id=47;
-- update Enable SEB browser and Suffix
UPDATE orientation SET x_position=7, y_position=11, width=5 WHERE config_attribute_id=57;
UPDATE orientation SET x_position=7, y_position=13, width=5 WHERE config_attribute_id=58;
-- insert Set VMWare Configuration
UPDATE orientation SET y_position=8 WHERE config_attribute_id=406;
UPDATE orientation SET y_position=9 WHERE config_attribute_id=407;
UPDATE orientation SET y_position=10 WHERE config_attribute_id=408;

View file

@ -1,5 +0,0 @@
-- -----------------------------------------------------
-- Remove all enableTouchExit attributes (9) from orientation
-- -----------------------------------------------------
DELETE FROM `orientation` WHERE `config_attribute_id`=9;
UPDATE orientation SET width=7 WHERE config_attribute_id=8;

View file

@ -897,8 +897,13 @@ sebserver.examconfig.props.label.hideBrowserWindowToolbar=Hide toolbar as defaul
sebserver.examconfig.props.label.hideBrowserWindowToolbar.tooltip=Hide browser window toolbar by default.<br/>It can be shown again by using the View menu or Alt-Command-T.
sebserver.examconfig.props.label.showMenuBar=Show menu bar (Mac)
sebserver.examconfig.props.label.showMenuBar.tooltip=Show the OS X menu bar to allow to access settings like Wi-Fi
sebserver.examconfig.props.label.browserWindowAllowAddressBar=Allow address bar for main window (Win)
sebserver.examconfig.props.label.newBrowserWindowAllowAddressBar=Allow address bar for additional windows (Win)
sebserver.examconfig.props.label.allowDeveloperConsole=Show developer tools in window menu (Win)
sebserver.examconfig.props.group.taskbar=SEB Taskbar/Dock
sebserver.examconfig.props.label.showSideMenu=Show side Menu
sebserver.examconfig.props.label.showTaskBar=Show SEB taskbar
sebserver.examconfig.props.label.showTaskBar.tooltip=The SEB task bar shows and switches between open browser windows,<br/> allowed resources and applications and displays additional controls
sebserver.examconfig.props.label.taskBarHeight=Taskbar/dock height
@ -965,6 +970,9 @@ sebserver.examconfig.props.label.newBrowserWindowByLinkPositioning.1=Center
sebserver.examconfig.props.label.newBrowserWindowByLinkPositioning.2=Right
sebserver.examconfig.props.group.browserSecurity=Browser security
sebserver.examconfig.props.label.allowFind=Allow text search
sebserver.examconfig.props.label.allowPDFReaderToolbar=Allow toolbar of internal PDF reader (Win)
sebserver.examconfig.props.label.allowPDFReaderToolbar.tooltip=This enables access to the print and download dialogs
sebserver.examconfig.props.label.enablePlugIns=Enable plug-ins (Win: only Flash)
sebserver.examconfig.props.label.enablePlugIns.tooltip=Enables web plugins (Mac) or just Flash (Win).<br/> For security reasons it\'s recommended to disable this option if you don\'t use any plugin/Flash content.
sebserver.examconfig.props.label.enableJavaScript=Enable JavaScript
@ -988,11 +996,27 @@ sebserver.examconfig.props.label.showReloadWarning=Show reload warning in exam
sebserver.examconfig.props.label.showReloadWarning.tooltip=User has to confirm reloading a web page with F5 or reload button
sebserver.examconfig.props.label.newBrowserWindowShowReloadWarning=Show reload warning in additional windows
sebserver.examconfig.props.label.newBrowserWindowShowReloadWarning.tooltip=User has to confirm reloading a web page with F5 or reload button
sebserver.examconfig.props.label.removeBrowserProfile=Remove profile (Win)
sebserver.examconfig.props.label.removeBrowserProfile.tooltip=Remove XULRunner browser profile (containing caches and also local storage) when quitting SEB
sebserver.examconfig.props.label.removeBrowserProfile=Delete cache when re-configuring or terminating SEB (Win) This setting is ignored if<br/>"Clear browser session when ending" in section Exam > Session Handling is deactivated!
sebserver.examconfig.props.label.removeBrowserProfile.tooltip=This setting is ignored if "Clear browser session when ending" in section Exam > Session Handling is deactivated!
sebserver.examconfig.props.label.removeLocalStorage=Disable local storage (Mac)
sebserver.examconfig.props.label.removeLocalStorage.tooltip=If your web application uses local storage, you have to be sure data is saved encrypted<br/> and removed when no longer needed as SEB doesn't remove local storage
sebserver.examconfig.props.group.examWindow=Restrictions in Exam Window
sebserver.examconfig.props.label.browserWindowShowURL=Show URLs
sebserver.examconfig.props.label.browserWindowShowURL.tooltip=For some exam scenarios, you may want to keep URLs secret
sebserver.examconfig.props.label.browserWindowShowURL.0=Never
sebserver.examconfig.props.label.browserWindowShowURL.1=OnlyLoadError
sebserver.examconfig.props.label.browserWindowShowURL.2=Before Title
sebserver.examconfig.props.label.browserWindowShowURL.3=Always
sebserver.examconfig.props.group.additionalWindow=Restrictions in Additional Windows
sebserver.examconfig.props.label.newBrowserWindowShowURL=Show URLs
sebserver.examconfig.props.label.newBrowserWindowShowURL.tooltip=For some exam scenarios, you may want to keep URLs secret
sebserver.examconfig.props.label.newBrowserWindowShowURL.0=Never
sebserver.examconfig.props.label.newBrowserWindowShowURL.1=OnlyLoadError
sebserver.examconfig.props.label.newBrowserWindowShowURL.2=Before Title
sebserver.examconfig.props.label.newBrowserWindowShowURL.3=Always
sebserver.examconfig.props.label.browserUserAgent=Suffix to be added to any user agent
sebserver.examconfig.props.group.userAgentDesktop=User agent for desktop mode
sebserver.examconfig.props.label.browserUserAgentWinDesktopMode.0=Desktop default
@ -1282,6 +1306,8 @@ sebserver.examconfig.props.label.insideSebEnableShutDown=Enable Shut down
sebserver.examconfig.props.label.insideSebEnableShutDown.tooltip=Activates the button "Shutdown"
sebserver.examconfig.props.label.insideSebEnableEaseOfAccess=Enable Ease of Access
sebserver.examconfig.props.label.insideSebEnableEaseOfAccess.tooltip=Shows options when the button "Ease of Access" in the lower left corner is clicked,<br/>which offers help e.g. to visually or aurally handicapped persons, like the Magnifier Glass.
sebserver.examconfig.props.label.setVmwareConfiguration=Set VMware configuration
sebserver.examconfig.props.label.setVmwareConfiguration.tooltip=Determines whether the configuration value for VMware Client Shade will be set by SEB
sebserver.examconfig.props.label.insideSebEnableVmWareClientShade=Enable VMware Client Shade
sebserver.examconfig.props.label.insideSebEnableVmWareClientShade.tooltip=Activates the "Shade" bar at the upper edge of a virtual desktop, if existent. If you're not using VMware, this setting doesn't have any effect.
sebserver.examconfig.props.label.insideSebEnableNetworkConnectionSelector=Enable network connection selector