Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2024.01.xx]: #10406: remove the 'Change Password' functionality if the logged in user account is managed via LDAP (#10407) #10420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions web/client/plugins/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

import './login/login.css';

import assign from 'object-assign';
import PropTypes from 'prop-types';
import React from 'react';

import epics from '../epics/login';
import { comparePendingChanges } from '../epics/pendingChanges';
import security from '../reducers/security';
import { Login, LoginNav, PasswordReset, UserDetails, UserMenu } from './login/index';
import {connect} from "../utils/PluginsUtils";
import {connect, createPlugin} from "../utils/PluginsUtils";
import {Glyphicon} from "react-bootstrap";
import {burgerMenuSelector} from "../selectors/controls";
import { isAdminUserSelector } from '../selectors/security';

/**
* Login Plugin. Allow to login/logout or show user info and reset password tools.
Expand All @@ -43,6 +43,7 @@ import {burgerMenuSelector} from "../selectors/controls";
*
* @prop {string} cfg.id identifier of the Plugin, by default `"mapstore-login-menu"`
* @prop {object} cfg.menuStyle inline style for the menu, by default:
* @prop {object} cfg.isUsingLDAP flag refers to if the user with type LDAP or not to manage show/hide change psasword, by default: false
* ```
* menuStyle: {
* zIndex: 30
Expand All @@ -52,20 +53,24 @@ import {burgerMenuSelector} from "../selectors/controls";
class LoginTool extends React.Component {
static propTypes = {
id: PropTypes.string,
menuStyle: PropTypes.object
menuStyle: PropTypes.object,
isAdmin: PropTypes.bool,
isUsingLDAP: PropTypes.bool
};

static defaultProps = {
id: "mapstore-login-menu",
menuStyle: {
zIndex: 30
}
},
isAdmin: false,
isUsingLDAP: false
};

render() {
return (<div id={this.props.id}>
<div style={this.props.menuStyle}>
<UserMenu />
<UserMenu showPasswordChange={!(!this.props.isAdmin && this.props.isUsingLDAP)} />
</div>
<UserDetails />
<PasswordReset />
Expand All @@ -74,40 +79,43 @@ class LoginTool extends React.Component {
}
}

export default {
LoginPlugin: assign(LoginTool, {
export default createPlugin('Login', {
component: connect((state) => ({isAdmin: isAdminUserSelector(state)}))(LoginTool),
containers: {
OmniBar: {
name: "login",
position: 3,
tool: connect(() => ({
tool: connect((state) => ({
renderButtonContent: () => {return <Glyphicon glyph="user" />; },
bsStyle: 'primary'
bsStyle: 'primary',
isAdmin: isAdminUserSelector(state)
}))(LoginNav),
tools: [UserDetails, PasswordReset, Login],
priority: 1
},
SidebarMenu: {
name: "login",
position: 2,
tool: connect(() => ({
tool: connect((state) => ({
bsStyle: 'tray',
tooltipPosition: 'left',
renderButtonContent: (props) => [<Glyphicon glyph="user" />, props.renderButtonText ? props.user && <span>props.user[props.displayName]</span> || <span>"Guest"</span> : null],
renderButtonText: true,
menuProps: {
noCaret: true
}
},
isAdmin: isAdminUserSelector(state)
}))(LoginNav),
selector: (state) => ({
style: { display: burgerMenuSelector(state) ? 'none' : null }
}),
tools: [UserDetails, PasswordReset, Login],
priority: 2
}
}),
},
reducers: {security},
epics: {
...epics,
comparePendingChanges
}
};
});
24 changes: 24 additions & 0 deletions web/client/plugins/__tests__/Login-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ describe('Login Plugin', () => {
// click on confirm button
TestUtils.Simulate.click(buttons[1]);
});
it('test hide change password in case LDAP user [not admin] ', () => {
const storeState = stateMocker(toggleControl('LoginForm', 'enabled'), loginSuccess({ User: { name: "Test", access_token: "some-token", role: 'USER' }}) );
const { Plugin } = getPluginForTest(Login, storeState);
ReactDOM.render(<Plugin isUsingLDAP />, document.getElementById("container"));
expect(document.querySelector('#mapstore-login-menu .glyphicon-user')).toBeTruthy();
const entries = document.querySelectorAll("#mapstore-login-menu ul li[role=\"presentation\"]");
expect(entries.length).toEqual(2); // user.info, user.logout
});
it('test show change password in case LDAP user [admin] ', () => {
const storeState = stateMocker(toggleControl('LoginForm', 'enabled'), loginSuccess({ User: { name: "Test", access_token: "some-token", role: 'ADMIN' }}) );
const { Plugin } = getPluginForTest(Login, storeState);
ReactDOM.render(<Plugin isUsingLDAP />, document.getElementById("container"));
expect(document.querySelector('#mapstore-login-menu .glyphicon-user')).toBeTruthy();
const entries = document.querySelectorAll("#mapstore-login-menu ul li[role=\"presentation\"]");
expect(entries.length).toEqual(3); // user.info, user.changePwd ,user.logout
});
it('test show change password in case ms user ', () => {
const storeState = stateMocker(toggleControl('LoginForm', 'enabled'), loginSuccess({ User: { name: "Test", access_token: "some-token", role: 'USER' }}) );
const { Plugin } = getPluginForTest(Login, storeState);
ReactDOM.render(<Plugin />, document.getElementById("container"));
expect(document.querySelector('#mapstore-login-menu .glyphicon-user')).toBeTruthy();
const entries = document.querySelectorAll("#mapstore-login-menu ul li[role=\"presentation\"]");
expect(entries.length).toEqual(3); // user.info, user.changePwd ,user.logout
});
});
describe('OmniBar menu entries', () => {
afterEach(() => {
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export const LoginNav = connect((state) => ({
const {currentProvider, providers = []} = stateProps;
const {type, showAccountInfo = false, showPasswordChange = false} = (providers ?? []).filter(({provider: provider}) => provider === currentProvider)?.[0] ?? {};
const isOpenID = type === "openID";
const isNormalLDAPUser = ownProps.isUsingLDAP && !ownProps.isAdmin;
return {
...ownProps,
...stateProps,
...dispatchProps,
showAccountInfo: isOpenID ? showAccountInfo : ownProps.showAccountInfo,
showPasswordChange: isOpenID ? showPasswordChange : ownProps.showPasswordChange
showPasswordChange: isOpenID ? showPasswordChange : isNormalLDAPUser ? false : ownProps.showPasswordChange
};
})(UserMenuComp);

Expand Down
Loading