-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Login HTML Notice: create notice (#720)
* 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
1 parent
0a06e17
commit 4558dce
Showing
13 changed files
with
323 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Source/Plugins/Core/com.equella.core/js/tsrc/components/SettingsMenuContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
80 changes: 80 additions & 0 deletions
80
Source/Plugins/Core/com.equella.core/js/tsrc/loginnotice/LoginNoticeConfigPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ugins/Core/com.equella.core/src/com/tle/core/settings/loginnotice/LoginNoticeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...e/com.equella.core/src/com/tle/core/settings/loginnotice/impl/LoginNoticeServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ce/Plugins/Core/com.equella.core/src/com/tle/web/api/loginnotice/LoginNoticeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.