aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/account
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-02-02 16:04:23 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-02-02 16:04:23 +0100
commit00fa8015834b6e92f7043b489689105f0dae70f7 (patch)
treefef755e800efedacf23472554d725e6e84052cc0 /server/sonar-web/src/main/js/apps/account
parent5c807b352c708657cdeefc3ce154f25fab624582 (diff)
downloadsonarqube-00fa8015834b6e92f7043b489689105f0dae70f7.tar.gz
sonarqube-00fa8015834b6e92f7043b489689105f0dae70f7.zip
SONAR-7250 use api/users/current on "My Account" page
Diffstat (limited to 'server/sonar-web/src/main/js/apps/account')
-rw-r--r--server/sonar-web/src/main/js/apps/account/components/Home.js12
-rw-r--r--server/sonar-web/src/main/js/apps/account/components/Security.js4
-rw-r--r--server/sonar-web/src/main/js/apps/account/containers/AccountApp.js27
-rw-r--r--server/sonar-web/src/main/js/apps/account/containers/SecurityContainer.js3
-rw-r--r--server/sonar-web/src/main/js/apps/account/store/actions.js24
-rw-r--r--server/sonar-web/src/main/js/apps/account/store/reducers.js9
6 files changed, 71 insertions, 8 deletions
diff --git a/server/sonar-web/src/main/js/apps/account/components/Home.js b/server/sonar-web/src/main/js/apps/account/components/Home.js
index 593618038db..28c8ec50118 100644
--- a/server/sonar-web/src/main/js/apps/account/components/Home.js
+++ b/server/sonar-web/src/main/js/apps/account/components/Home.js
@@ -56,6 +56,18 @@ const Home = ({ user, favorites, issueFilters, measureFilters }) => (
<section className="huge-spacer-top">
<h2 className="spacer-bottom">{translate('my_profile.scm_accounts')}</h2>
<ul id="scm-accounts">
+ <li
+ className="little-spacer-bottom text-ellipsis"
+ title={user.login}>
+ {user.login}
+ </li>
+ {user.email && (
+ <li
+ className="little-spacer-bottom text-ellipsis"
+ title={user.email}>
+ {user.email}
+ </li>
+ )}
{user.scmAccounts.map(scmAccount => (
<li
key={scmAccount}
diff --git a/server/sonar-web/src/main/js/apps/account/components/Security.js b/server/sonar-web/src/main/js/apps/account/components/Security.js
index 44938188c5c..52f0a1a9e74 100644
--- a/server/sonar-web/src/main/js/apps/account/components/Security.js
+++ b/server/sonar-web/src/main/js/apps/account/components/Security.js
@@ -22,7 +22,7 @@ import React from 'react';
import Password from './Password';
import Tokens from './Tokens';
-export default function Security ({ user }) {
+export default function Security ({ user, canChangePassword }) {
return (
<div className="page page-limited">
<div className="columns">
@@ -30,7 +30,7 @@ export default function Security ({ user }) {
<Tokens user={user}/>
</div>
- {user.canChangePassword && (
+ {canChangePassword && (
<div className="column-half">
<Password user={user}/>
</div>
diff --git a/server/sonar-web/src/main/js/apps/account/containers/AccountApp.js b/server/sonar-web/src/main/js/apps/account/containers/AccountApp.js
index 9559d933640..7b30e1479a2 100644
--- a/server/sonar-web/src/main/js/apps/account/containers/AccountApp.js
+++ b/server/sonar-web/src/main/js/apps/account/containers/AccountApp.js
@@ -18,14 +18,17 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import React, { Component, cloneElement } from 'react';
+import { connect } from 'react-redux';
import Nav from '../components/Nav';
+import { fetchUser } from '../store/actions';
import { getIssueFilters } from '../../../api/issues';
-export default class AccountApp extends Component {
+class AccountApp extends Component {
state = {};
componentDidMount () {
+ this.props.fetchUser();
this.fetchFavoriteIssueFilters();
}
@@ -37,8 +40,13 @@ export default class AccountApp extends Component {
}
render () {
- const { user } = window.sonarqube;
- const { favorites } = user;
+ const { user } = this.props;
+
+ if (!user) {
+ return null;
+ }
+
+ const { favorites } = window.sonarqube.user;
const { issueFilters } = this.state;
const children = cloneElement(this.props.children, {
measureFilters: user.favoriteMeasureFilters,
@@ -55,3 +63,16 @@ export default class AccountApp extends Component {
);
}
}
+
+function mapStateToProps (state) {
+ return { user: state.user };
+}
+
+function mapDispatchToProps (dispatch) {
+ return { fetchUser: () => dispatch(fetchUser()) };
+}
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(AccountApp);
diff --git a/server/sonar-web/src/main/js/apps/account/containers/SecurityContainer.js b/server/sonar-web/src/main/js/apps/account/containers/SecurityContainer.js
index 2e6561506f3..72bf0c1e4fa 100644
--- a/server/sonar-web/src/main/js/apps/account/containers/SecurityContainer.js
+++ b/server/sonar-web/src/main/js/apps/account/containers/SecurityContainer.js
@@ -23,7 +23,8 @@ import Security from './../components/Security';
function mapStateToProps (state) {
return {
- user: state.user
+ user: state.user,
+ canChangePassword: window.sonarqube.user.canChangePassword
};
}
diff --git a/server/sonar-web/src/main/js/apps/account/store/actions.js b/server/sonar-web/src/main/js/apps/account/store/actions.js
index bee94192a5c..f241d4c22c5 100644
--- a/server/sonar-web/src/main/js/apps/account/store/actions.js
+++ b/server/sonar-web/src/main/js/apps/account/store/actions.js
@@ -17,9 +17,26 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { getCurrentUser } from '../../../api/users';
+
+export const REQUEST_USER = 'REQUEST_USER';
+export const RECEIVE_USER = 'RECEIVE_USER';
export const ADD_PROJECT_NOTIFICATIONS = 'ADD_PROJECT_NOTIFICATIONS';
export const REMOVE_PROJECT_NOTIFICATIONS = 'REMOVE_PROJECT_NOTIFICATIONS';
+export function requestUser () {
+ return {
+ type: REQUEST_USER
+ };
+}
+
+export function receiveUser (user) {
+ return {
+ type: RECEIVE_USER,
+ user
+ };
+}
+
export function addProjectNotifications (project) {
return {
type: ADD_PROJECT_NOTIFICATIONS,
@@ -33,3 +50,10 @@ export function removeProjectNotifications (project) {
project
};
}
+
+export function fetchUser () {
+ return dispatch => {
+ dispatch(requestUser());
+ return getCurrentUser().then(user => dispatch(receiveUser(user)));
+ };
+}
diff --git a/server/sonar-web/src/main/js/apps/account/store/reducers.js b/server/sonar-web/src/main/js/apps/account/store/reducers.js
index 626a3875ba4..813dcf15b97 100644
--- a/server/sonar-web/src/main/js/apps/account/store/reducers.js
+++ b/server/sonar-web/src/main/js/apps/account/store/reducers.js
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { ADD_PROJECT_NOTIFICATIONS, REMOVE_PROJECT_NOTIFICATIONS } from './actions';
+import { RECEIVE_USER, ADD_PROJECT_NOTIFICATIONS, REMOVE_PROJECT_NOTIFICATIONS } from './actions';
function addProjectNotifications (state, project) {
const found = state.find(notification => {
@@ -48,12 +48,17 @@ function removeProjectNotifications (state, project) {
}
export const initialState = {
- user: window.sonarqube.user,
+ user: null,
projectNotifications: window.sonarqube.notifications.project
};
export default function (state = initialState, action) {
switch (action.type) {
+ case RECEIVE_USER:
+ return {
+ ...state,
+ user: action.user
+ };
case ADD_PROJECT_NOTIFICATIONS:
return {
...state,