Skip to content

Commit

Permalink
Login HTML Notice: create notice (#720)
Browse files Browse the repository at this point in the history
* Add route and menu option for login notice editor

* Add Rest API and Service

* Create initial prototype of login notice editor page

* Add IDs to the textfield and button, remove page reload

* Remove Iterable from single permission check

* Add apereo headers

* Make changes suggested in edalex-ian's code review

-Remove unnecessary braces in LoginNoticeConfigPage.tsx
-Reword login notice settings description
-Remove warning suppression
-Minor formatting changes to LoginNoticeServiceImpl.java

* Refactor styling into SettingsMenuContainer

* Remove unnecessary braces
  • Loading branch information
SammyIsConfused authored Jan 25, 2019
1 parent 0a06e17 commit 4558dce
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Source/Plugins/Core/com.equella.core/js/src/MainUI/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import OEQ.Utils.Polyfills (polyfill)
import React (component, unsafeCreateLeafElement)
import React.DOM (div')
import Routing.PushState (matchesWith)
import TSComponents (courseEdit, coursesPage, themePageClass)
import TSComponents (courseEdit, coursesPage, themePageClass, loginNoticeConfigPageClass)
import Web.HTML (window)
import Web.HTML.Location (pathname)
import Web.HTML.Window (location)
Expand Down Expand Up @@ -60,6 +60,7 @@ main = do
CoursesPage -> coursesPage
NewCourse -> courseEdit Nothing
ThemePage -> unsafeCreateLeafElement themePageClass {bridge:tsBridge}
LoginNoticeConfigPage -> unsafeCreateLeafElement loginNoticeConfigPageClass {bridge:tsBridge}
CourseEdit cid -> courseEdit $ Just cid
ViewItemPage (ItemRef uuid version) -> viewItemPage {uuid,version}
LegacyPage page -> legacy {page}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ data Route =
CourseEdit String |
ViewItemPage ItemRef |
ThemePage |
NewCourse
NewCourse |
LoginNoticeConfigPage

navGlobals :: forall route. {nav::PushStateInterface, preventNav :: Ref (EffectFn1 route Boolean)}
navGlobals = unsafePerformEffect do
Expand Down Expand Up @@ -80,7 +81,8 @@ routeMatch =
NewCourse <$ (lit "course" *> lit "new") <|>
CourseEdit <$> (lit "course" *> str <* lit "edit") <|>
CoursesPage <$ (lit "course") <|>
ThemePage <$ (lit "themeconfiguration"))
ThemePage <$ (lit "themeconfiguration") <|>
LoginNoticeConfigPage <$ (lit "loginconfiguration"))
<|> (LegacyPage <$> legacyRoute)


Expand Down Expand Up @@ -123,6 +125,7 @@ routeURI r = (case r of
CoursesPage -> "page/course"
NewCourse -> "page/course/new"
ThemePage -> "page/themeconfiguration"
LoginNoticeConfigPage -> "page/loginconfiguration"
CourseEdit cid -> "page/course/" <> cid <> "/edit"
ViewItemPage (ItemRef uuid version) -> "integ/gen/" <> uuid <> "/" <> show version
LegacyPage (LegacyURI path params) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exports.editCourse = require("course/EditCourse").default;
exports.appBarQueryClass = require("components/AppBarQuery").default;
exports.courseSelectClass = require("components/CourseSelect").default;
exports.themePageClass = require("theme/ThemePage").default;
exports.loginNoticeConfigPageClass = require("loginnotice/LoginNoticeConfigPage").default;
2 changes: 2 additions & 0 deletions Source/Plugins/Core/com.equella.core/js/src/TSComponents.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ foreign import courseSelectClass :: forall a. ReactClass a

foreign import themePageClass :: forall a. ReactClass a

foreign import loginNoticeConfigPageClass :: forall a. ReactClass a

coursesPage :: ReactElement
coursesPage = unsafeCreateLeafElement searchCourses {store:store, bridge: tsBridge}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from "react";
import {createStyles, Paper, withStyles, WithStyles} from "@material-ui/core";

const styles = createStyles({
container: {
margin: "8px",
padding: "8px"
}
});

class SettingsMenuContainer extends React.Component<WithStyles<typeof styles>> {

constructor(props: WithStyles<typeof styles>) {
super(props);
};

render() {
const styles = this.props.classes;
return (
<Paper className={styles.container}>
{this.props.children}
</Paper>
);
}
}

export default withStyles(styles)(SettingsMenuContainer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as React from "react";
import {Bridge} from "../api/bridge";
import {prepLangStrings} from "../util/langstrings";
import {Button, Grid, TextField} from "@material-ui/core";
import axios, {AxiosResponse} from "axios";
import {Config} from "../config";
import SettingsMenuContainer from "../components/SettingsMenuContainer";

interface LoginNoticeConfigPageProps {
bridge: Bridge;
}

interface LoginNoticeConfigPageState {
notice?: string
}

export const strings = prepLangStrings("loginnoticepage",
{
title: "Login Notice Editor",
label: "Login Notice"
}
);

class LoginNoticeConfigPage extends React.Component<LoginNoticeConfigPageProps, LoginNoticeConfigPageState> {

constructor(props:LoginNoticeConfigPageProps) {
super(props);
};

state: LoginNoticeConfigPageState = {
notice: ""
};

handleSubmitNotice = () => {
axios.put(`${Config.baseUrl}api/loginnotice/settings/`, this.state.notice);
};

handleTextFieldChange = (e: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement) => {
this.setState({notice: e.value});
};

componentDidMount = () => {
axios
.get(`${Config.baseUrl}api/loginnotice/settings/`)
.then((response: AxiosResponse) =>
{
this.setState({notice: response.data});
});
};

render() {
const {Template} = this.props.bridge;
return (
<Template title={strings.title}>
<SettingsMenuContainer>
<Grid container spacing={8} direction="column">
<Grid item>
<TextField id="noticeField"
label={strings.label}
rows= "10"
variant="outlined"
multiline autoFocus
placeholder="<div></div>"
onChange={e => this.handleTextFieldChange(e.target)}
value={this.state.notice}/>
</Grid>
<Grid item>
<Button id="applyButton"
onClick={this.handleSubmitNotice}
variant="contained">
Apply
</Button>
</Grid>
</Grid>
</SettingsMenuContainer>
</Template>
);
}
}
export default LoginNoticeConfigPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,8 @@ log.uploading=Uploading resource {0}
loggedin=Logged in
login.asuser=Login as user\:
login.description=Configure login settings and authentication by IP address. Author a Login notice to display to users on login
loginnotice.settings.title=Login Notice Settings
loginnotice.settings.description=Configuration of notices during the login process.
login.enable=Enable SSL
login.enableanonacl=Enable IP address and HTTP referrer ACLs for anonymous requests
login.enableloginip=Enable login via IP address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.tle.web.settings
import com.tle.common.connectors.ConnectorConstants.{PRIV_CREATE_CONNECTOR, PRIV_EDIT_CONNECTOR}
import com.tle.common.externaltools.constants.ExternalToolConstants
import com.tle.common.lti.consumers.LtiConsumerConstants
import com.tle.common.security.SecurityConstants
import com.tle.common.userscripts.UserScriptsConstants
import com.tle.core.activation.service.CourseInfoService
import com.tle.core.db.{DB, RunWithDB}
Expand Down Expand Up @@ -60,7 +59,10 @@ object SettingsList {
}

val uiSettings = CoreSettingsRest("ui", "ui", "uisettings.name", "uisettings.desc", "api/settings/ui",
AclChecks.filterNonGrantedPrivileges(Iterable("EDIT_SYSTEM_SETTINGS"), false))
AclChecks.filterNonGrantedPrivileges(Iterable("EDIT_SYSTEM_SETTINGS"),true))

val loginNoticeSettings = CoreSettingsPage("loginnotice", General, "loginnotice.settings.title", "loginnotice.settings.description","page/loginconfiguration",
() => !aclManager.filterNonGrantedPrivileges("EDIT_SYSTEM_SETTINGS").isEmpty)

val echoSettings = CoreSettingsPage("echo", Integration, "echo.settings.title", "echo.settings.description",
"access/echoservers.do", () => !aclManager.filterNonGrantedPrivileges(EchoConstants.PRIV_CREATE_ECHO, EchoConstants.PRIV_EDIT_ECHO).isEmpty)
Expand Down Expand Up @@ -88,7 +90,7 @@ object SettingsList {

val allSettings : mutable.Buffer[EditableSettings] = mutable.Buffer(
connectorSettings, echoSettings, ltiConsumersSettings, userScriptSettings,
oauthSettings, htmlEditorSettings, externalToolsSettings, uiSettings,
oauthSettings, htmlEditorSettings, externalToolsSettings, uiSettings, loginNoticeSettings,

CoreSettingsPage("shortcuts", General, "shortcuts.settings.title", "shortcuts.settings.description",
"access/shortcuturlssettings.do", shortcutPrivProvider.isAuthorised),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017 Apereo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tle.core.settings.loginnotice;

public interface LoginNoticeService
{
String getNotice();

void setNotice(String notice);

void deleteNotice();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2017 Apereo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tle.core.settings.loginnotice.impl;

import com.tle.core.guice.Bind;
import com.tle.core.security.TLEAclManager;
import com.tle.core.settings.loginnotice.LoginNoticeService;
import com.tle.core.settings.service.ConfigurationService;
import com.tle.exceptions.PrivilegeRequiredException;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Collections;

@Singleton
@Bind(LoginNoticeService.class)
public class LoginNoticeServiceImpl implements LoginNoticeService
{
@Inject
TLEAclManager tleAclManager;
@Inject
ConfigurationService configurationService;

private static final String PERMISSION_KEY = "EDIT_SYSTEM_SETTINGS";
private static final String LOGIN_NOTICE_KEY = "login.notice.settings";

@Override
public String getNotice()
{
String loginNotice = configurationService.getProperty(LOGIN_NOTICE_KEY);
if(loginNotice != null)
{
return loginNotice;
}
return "";
}

@Override
public void setNotice(String notice)
{
checkPermissions();
configurationService.setProperty(LOGIN_NOTICE_KEY, notice);
}

@Override
public void deleteNotice()
{
checkPermissions();
configurationService.deleteProperty(LOGIN_NOTICE_KEY);
}

private void checkPermissions() {
if (tleAclManager.filterNonGrantedPrivileges(Collections.singleton(PERMISSION_KEY), false).isEmpty()) {
throw new PrivilegeRequiredException(PERMISSION_KEY);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2017 Apereo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tle.web.api.loginnotice;

import io.swagger.annotations.Api;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;

/**
* @author Samantha Fisher
*/

@Path("loginnotice/")
@Api("Login Notice")
public interface LoginNoticeResource
{
@GET
@Produces("text/plain")
@Path("settings")
Response retrieveNotice();

@PUT
@Path("settings")
Response setNotice(String loginNotice);

@DELETE
@Path("settings")
Response deleteNotice();
}
Loading

0 comments on commit 4558dce

Please sign in to comment.