* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import $ from 'jquery';
-import { post, postJSON } from '../helpers/request.js';
+import { getJSON, post } from '../helpers/request.js';
export function getCurrentUser () {
const url = baseUrl + '/api/users/current';
- return $.get(url);
+ return getJSON(url);
}
export function changePassword (login, password, previousPassword) {
<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}
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">
<Tokens user={user}/>
</div>
- {user.canChangePassword && (
+ {canChangePassword && (
<div className="column-half">
<Password user={user}/>
</div>
* 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();
}
}
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,
);
}
}
+
+function mapStateToProps (state) {
+ return { user: state.user };
+}
+
+function mapDispatchToProps (dispatch) {
+ return { fetchUser: () => dispatch(fetchUser()) };
+}
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(AccountApp);
function mapStateToProps (state) {
return {
- user: state.user
+ user: state.user,
+ canChangePassword: window.sonarqube.user.canChangePassword
};
}
* 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,
project
};
}
+
+export function fetchUser () {
+ return dispatch => {
+ dispatch(requestUser());
+ return getCurrentUser().then(user => dispatch(receiveUser(user)));
+ };
+}
* 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 => {
}
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,
<% content_for :extra_script do %>
<script>
window.sonarqube.user = {
- login: '<%= escape_javascript current_user.login -%>',
- name: '<%= escape_javascript current_user.name -%>',
- email: '<%= escape_javascript current_user.email -%>',
canChangePassword: <%= User.editable_password? ? 'true' : 'false' -%>,
- groups: [
- <% current_user.groups.sort.each do |group| -%>
- '<%= escape_javascript group.name -%>',
- <% end -%>
- ],
- scmAccounts: [
- <% current_user.full_scm_accounts.sort.each do |scm_account| -%>
- '<%= escape_javascript scm_account -%>',
- <% end -%>
- ],
favorites: [
<% current_user.favourites.each_with_index do |f, index| %>
{