import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.db.user.UserDto;
+import org.sonar.server.issue.ws.AvatarResolver;
import org.sonar.server.permission.ProjectId;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.WsPermissions.UsersWsResponse;
+import static com.google.common.base.Strings.emptyToNull;
import static java.util.Collections.emptyList;
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE;
private final DbClient dbClient;
private final UserSession userSession;
private final PermissionWsSupport support;
+ private final AvatarResolver avatarResolver;
- public UsersAction(DbClient dbClient, UserSession userSession, PermissionWsSupport support) {
+ public UsersAction(DbClient dbClient, UserSession userSession, PermissionWsSupport support, AvatarResolver avatarResolver) {
this.dbClient = dbClient;
this.userSession = userSession;
this.support = support;
+ this.avatarResolver = avatarResolver;
}
@Override
return permissionQuery.build();
}
- private static UsersWsResponse buildResponse(List<UserDto> users, List<UserPermissionDto> userPermissions, Paging paging) {
+ private UsersWsResponse buildResponse(List<UserDto> users, List<UserPermissionDto> userPermissions, Paging paging) {
Multimap<Integer, String> permissionsByUserId = TreeMultimap.create();
userPermissions.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission()));
.setLogin(user.getLogin())
.addAllPermissions(permissionsByUserId.get(user.getId()));
setNullable(user.getEmail(), userResponse::setEmail);
+ setNullable(emptyToNull(user.getEmail()), u -> userResponse.setAvatar(avatarResolver.create(user)));
setNullable(user.getName(), userResponse::setName);
});
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.permission.template.PermissionTemplateUserDto;
import org.sonar.db.user.UserDto;
+import org.sonar.server.issue.ws.AvatarResolver;
import org.sonar.server.permission.ws.PermissionWsSupport;
import org.sonar.server.permission.ws.PermissionsWsAction;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsPermissions;
import org.sonarqube.ws.WsPermissions.UsersWsResponse;
+import static com.google.common.base.Strings.emptyToNull;
import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
private final DbClient dbClient;
private final UserSession userSession;
private final PermissionWsSupport support;
+ private final AvatarResolver avatarResolver;
- public TemplateUsersAction(DbClient dbClient, UserSession userSession, PermissionWsSupport support) {
+ public TemplateUsersAction(DbClient dbClient, UserSession userSession, PermissionWsSupport support, AvatarResolver avatarResolver) {
this.dbClient = dbClient;
this.userSession = userSession;
this.support = support;
+ this.avatarResolver = avatarResolver;
}
@Override
return query.build();
}
- private static WsPermissions.UsersWsResponse buildResponse(List<UserDto> users, List<PermissionTemplateUserDto> permissionTemplateUsers, Paging paging) {
+ private WsPermissions.UsersWsResponse buildResponse(List<UserDto> users, List<PermissionTemplateUserDto> permissionTemplateUsers, Paging paging) {
Multimap<Integer, String> permissionsByUserId = TreeMultimap.create();
permissionTemplateUsers.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(), userPermission.getPermission()));
.addAllPermissions(permissionsByUserId.get(user.getId()));
setNullable(user.getEmail(), userResponse::setEmail);
setNullable(user.getName(), userResponse::setName);
+ setNullable(emptyToNull(user.getEmail()), u -> userResponse.setAvatar(avatarResolver.create(user)));
});
responseBuilder.getPagingBuilder()
.setPageIndex(paging.pageIndex())
import org.sonar.db.DbSession;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.user.UserDto;
+import org.sonar.server.issue.ws.AvatarResolver;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.WsUsers.CurrentWsResponse;
private final UserSession userSession;
private final DbClient dbClient;
private final DefaultOrganizationProvider defaultOrganizationProvider;
+ private final AvatarResolver avatarResolver;
- public CurrentAction(UserSession userSession, DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public CurrentAction(UserSession userSession, DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider, AvatarResolver avatarResolver) {
this.userSession = userSession;
this.dbClient = dbClient;
this.defaultOrganizationProvider = defaultOrganizationProvider;
+ this.avatarResolver = avatarResolver;
}
@Override
.setPermissions(Permissions.newBuilder().addAllGlobal(getGlobalPermissions()).build())
.setShowOnboardingTutorial(!user.isOnboarded());
setNullable(emptyToNull(user.getEmail()), builder::setEmail);
+ setNullable(emptyToNull(user.getEmail()), u -> builder.setAvatar(avatarResolver.create(user)));
setNullable(user.getExternalIdentity(), builder::setExternalIdentity);
setNullable(user.getExternalIdentityProvider(), builder::setExternalProvider);
return builder.build();
"login": "admin",
"name": "Administrator",
"email": "admin@admin.com",
- "permissions": [
- "codeviewer"
- ]
+ "avatar": "64e1b8d34f425d19e1ee2ea7236d3028",
+ "permissions": ["codeviewer"]
},
{
"login": "george.orwell",
"name": "George Orwell",
"email": "george.orwell@1984.net",
- "permissions": [
- "admin",
- "codeviewer"
- ]
+ "avatar": "583af86a274c1027ef078cada831babf",
+ "permissions": ["admin", "codeviewer"]
}
]
}
"login": "admin",
"name": "Administrator",
"email": "admin@admin.com",
- "permissions": [
- "admin",
- "gateadmin",
- "profileadmin"
- ]
+ "avatar": "64e1b8d34f425d19e1ee2ea7236d3028",
+ "permissions": ["admin", "gateadmin", "profileadmin"]
},
{
"login": "george.orwell",
"name": "George Orwell",
"email": "george.orwell@1984.net",
- "permissions": [
- "scan"
- ]
+ "avatar": "583af86a274c1027ef078cada831babf",
+ "permissions": ["scan"]
}
]
}
-
"login": "obiwan.kenobi",
"name": "Obiwan Kenobi",
"email": "obiwan.kenobi@starwars.com",
+ "avatar": "f5aa64437a1821ffe8b563099d506aef",
"local": true,
"externalIdentity": "obiwan.kenobi",
"externalProvider": "sonarqube",
"showOnboardingTutorial": false,
- "scmAccounts": [
- "obiwan:github",
- "obiwan:bitbucket"
- ],
- "groups": [
- "Jedi", "Rebel"
- ],
+ "scmAccounts": ["obiwan:github", "obiwan:bitbucket"],
+ "groups": ["Jedi", "Rebel"],
"permissions": {
- "global": [
- "profileadmin",
- "scan"
- ]
+ "global": ["profileadmin", "scan"]
}
}
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
+import org.sonar.server.issue.ws.AvatarResolverImpl;
import org.sonar.server.permission.ws.template.TemplateGroupsAction;
import org.sonar.server.permission.ws.template.TemplateUsersAction;
import org.sonar.server.user.UserSession;
PermissionWsSupport permissionWsSupport = mock(PermissionWsSupport.class);
ws = new WsTester(new PermissionsWs(
- new TemplateUsersAction(dbClient, userSession, permissionWsSupport),
+ new TemplateUsersAction(dbClient, userSession, permissionWsSupport, new AvatarResolverImpl()),
new TemplateGroupsAction(dbClient, userSession, permissionWsSupport)));
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
+import org.sonar.server.issue.ws.AvatarResolverImpl;
import static java.lang.String.format;
import static org.apache.commons.lang.StringUtils.countMatches;
@Override
protected UsersAction buildWsAction() {
- return new UsersAction(db.getDbClient(), userSession, newPermissionWsSupport());
+ return new UsersAction(db.getDbClient(), userSession, newPermissionWsSupport(), new AvatarResolverImpl());
}
@Test
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
+import org.sonar.server.issue.ws.AvatarResolverImpl;
import org.sonar.server.permission.ws.BasePermissionWsTest;
import org.sonar.server.ws.TestRequest;
import org.sonarqube.ws.WsPermissions;
@Override
protected TemplateUsersAction buildWsAction() {
- return new TemplateUsersAction(db.getDbClient(), userSession, newPermissionWsSupport());
+ return new TemplateUsersAction(db.getDbClient(), userSession, newPermissionWsSupport(), new AvatarResolverImpl());
}
@Test
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
+import org.sonar.server.issue.ws.AvatarResolverImpl;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
private DbClient dbClient = db.getDbClient();
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private WsActionTester ws = new WsActionTester(new CurrentAction(userSessionRule, dbClient, defaultOrganizationProvider));
+ private WsActionTester ws = new WsActionTester(new CurrentAction(userSessionRule, dbClient, defaultOrganizationProvider, new AvatarResolverImpl()));
@Test
public void return_user_info() {
CurrentWsResponse response = call();
assertThat(response)
- .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::getEmail, CurrentWsResponse::getLocal,
+ .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::getEmail, CurrentWsResponse::getAvatar, CurrentWsResponse::getLocal,
CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getScmAccountsList, CurrentWsResponse::getShowOnboardingTutorial)
- .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", "obiwan.kenobi@starwars.com", true, "obiwan", "sonarqube",
+ .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", "obiwan.kenobi@starwars.com", "f5aa64437a1821ffe8b563099d506aef", true, "obiwan", "sonarqube",
newArrayList("obiwan:github", "obiwan:bitbucket"), true);
}
CurrentWsResponse response = call();
assertThat(response)
- .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::getLocal,
+ .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::hasAvatar, CurrentWsResponse::getLocal,
CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider)
- .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", true, "obiwan", "sonarqube");
+ .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", false, true, "obiwan", "sonarqube");
assertThat(response.hasEmail()).isFalse();
assertThat(response.getScmAccountsList()).isEmpty();
assertThat(response.getGroupsList()).isEmpty();
WsTester tester = new WsTester(new UsersWs(
new CreateAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule),
new UpdateAction(mock(UserUpdater.class), userSessionRule, mock(UserJsonWriter.class), mock(DbClient.class)),
- new CurrentAction(userSessionRule, mock(DbClient.class), mock(DefaultOrganizationProvider.class)),
+ new CurrentAction(userSessionRule, mock(DbClient.class), mock(DefaultOrganizationProvider.class), mock(AvatarResolver.class)),
new ChangePasswordAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule),
new SearchAction(userSessionRule, mock(UserIndex.class), mock(DbClient.class), mock(AvatarResolver.class))));
controller = tester.controller("api/users");
"babel-polyfill": "6.26.0",
"backbone": "1.2.3",
"backbone.marionette": "2.4.3",
- "blueimp-md5": "1.1.1",
"classnames": "2.2.5",
"clipboard": "1.7.1",
"create-react-class": "15.6.2",
/*::
type CurrentUser = {
+ avatar?: string,
email?: string,
isLoggedIn: boolean,
name: string
className={classNames('dropdown js-user-authenticated', { open: this.state.open })}
ref={node => (this.node = node)}>
<a className="dropdown-toggle navbar-avatar" href="#" onClick={this.toggleDropdown}>
- <Avatar email={currentUser.email} name={currentUser.name} size={24} />
+ <Avatar hash={currentUser.avatar} name={currentUser.name} size={24} />
</a>
{this.state.open && (
<ul className="dropdown-menu dropdown-menu-right">
import { shallow } from 'enzyme';
import GlobalNavUser from '../GlobalNavUser';
-const currentUser = { isLoggedIn: true, name: 'foo', email: 'foo@bar.baz' };
+const currentUser = { avatar: 'abcd1234', isLoggedIn: true, name: 'foo', email: 'foo@bar.baz' };
const organizations = [
{ key: 'myorg', name: 'MyOrg' },
{ key: 'foo', name: 'Foo' },
onClick={[Function]}
>
<Connect(Avatar)
- email="foo@bar.baz"
+ hash="abcd1234"
name="foo"
size={24}
/>
onClick={[Function]}
>
<Connect(Avatar)
- email="foo@bar.baz"
+ hash="abcd1234"
name="foo"
size={24}
/>
onClick={[Function]}
>
<Connect(Avatar)
- email="foo@bar.baz"
+ hash="abcd1234"
name="foo"
size={24}
/>
onClick={[Function]}
>
<Connect(Avatar)
- email="foo@bar.baz"
+ hash="abcd1234"
name="foo"
size={24}
/>
return (
<div className="account-user">
<div id="avatar" className="pull-left account-user-avatar">
- <Avatar email={user.email} name={user.name} size={60} />
+ <Avatar hash={user.avatar} name={user.name} size={60} />
</div>
<h1 id="name" className="pull-left">
{user.name}
renderAssigneeOption = (option /*: { avatar?: string, email?: string, label: string } */) => (
<span>
- {(option.avatar != null || option.email != null) && (
+ {option.avatar != null && (
<Avatar
className="little-spacer-right"
- email={option.email}
hash={option.avatar}
name={option.label}
size={16}
return (
<tr>
<td className="thin nowrap">
- <Avatar hash={member.avatar} email={member.email} name={member.name} size={AVATAR_SIZE} />
+ <Avatar hash={member.avatar} name={member.name} size={AVATAR_SIZE} />
</td>
<td className="nowrap text-middle">
<strong>{member.name}</strong>
<td className="nowrap">
{!isCreator && (
<Avatar
- email={user.email}
+ hash={user.avatar}
name={user.name}
size={36}
className="text-middle big-spacer-right"
onMouseEnter={this.handleMouseEnter}
onMouseMove={this.handleMouseMove}
title={user.name}>
- <Avatar hash={user.avatar} email={user.email} name={user.name} size={AVATAR_SIZE} />
+ <Avatar hash={user.avatar} name={user.name} size={AVATAR_SIZE} />
<strong className="spacer-left">{this.props.children}</strong>
<span className="note little-spacer-left">{user.login}</span>
</div>
{user &&
user.login && (
<div className="Select-value-label">
- <Avatar hash={user.avatar} email={user.email} name={user.name} size={AVATAR_SIZE} />
+ <Avatar hash={user.avatar} name={user.name} size={AVATAR_SIZE} />
<strong className="spacer-left">{this.props.children}</strong>
<span className="note little-spacer-left">{user.login}</span>
</div>
title="Administrator"
>
<Connect(Avatar)
- email="admin@admin.ch"
name="Administrator"
size={16}
/>
className="Select-value-label"
>
<Connect(Avatar)
- email="admin@admin.ch"
name="Administrator"
size={16}
/>
<td class="thin nowrap">
- <div>{{avatarHelper email name 36}}</div>
+ <div>{{avatarHelper avatar name 36}}</div>
</td>
<td>
{this.state.users.map(user => (
<SelectListItem key={user.login} item={user.login}>
{!!user.login && (
- <Avatar
- className="spacer-right"
- email={user.email}
- hash={user.avatar}
- name={user.name}
- size={16}
- />
+ <Avatar className="spacer-right" hash={user.avatar} name={user.name} size={16} />
)}
<span
className="vertical-middle"
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import React from 'react';
-import PropTypes from 'prop-types';
-import { connect } from 'react-redux';
-import md5 from 'blueimp-md5';
-import classNames from 'classnames';
-import { getGlobalSettingValue } from '../../store/rootReducer';
-
-function stringToColor(str) {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- hash = str.charCodeAt(i) + ((hash << 5) - hash);
- }
- let color = '#';
- for (let i = 0; i < 3; i++) {
- const value = (hash >> (i * 8)) & 0xff;
- color += ('00' + value.toString(16)).substr(-2);
- }
- return color;
-}
-
-function getTextColor(background) {
- const rgb = parseInt(background.substr(1), 16);
- const r = (rgb >> 16) & 0xff;
- const g = (rgb >> 8) & 0xff;
- const b = (rgb >> 0) & 0xff;
- const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
- return luma > 140 ? '#222' : '#fff';
-}
-
-class Avatar extends React.PureComponent {
- static propTypes = {
- enableGravatar: PropTypes.bool.isRequired,
- gravatarServerUrl: PropTypes.string.isRequired,
- email: PropTypes.string,
- hash: PropTypes.string,
- name: PropTypes.string.isRequired,
- size: PropTypes.number.isRequired,
- className: PropTypes.string
- };
-
- renderFallback() {
- const className = classNames(this.props.className, 'rounded');
- const color = stringToColor(this.props.name);
-
- let text = '';
- const words = this.props.name.split(/\s+/).filter(word => word.length > 0);
- if (words.length >= 2) {
- text = words[0][0] + words[1][0];
- } else if (this.props.name.length > 0) {
- text = this.props.name[0];
- }
-
- return (
- <div
- className={className}
- style={{
- backgroundColor: color,
- color: getTextColor(color),
- display: 'inline-block',
- fontSize: Math.min(this.props.size / 2, 14),
- fontWeight: 'normal',
- height: this.props.size,
- lineHeight: `${this.props.size}px`,
- textAlign: 'center',
- verticalAlign: 'top',
- width: this.props.size
- }}>
- {text.toUpperCase()}
- </div>
- );
- }
-
- render() {
- if (!this.props.enableGravatar) {
- return this.renderFallback();
- }
-
- const emailHash = this.props.hash || md5((this.props.email || '').toLowerCase()).trim();
- const url = this.props.gravatarServerUrl
- .replace('{EMAIL_MD5}', emailHash)
- .replace('{SIZE}', this.props.size * 2);
-
- const className = classNames(this.props.className, 'rounded');
-
- return (
- <img
- className={className}
- src={url}
- width={this.props.size}
- height={this.props.size}
- alt={this.props.email}
- />
- );
- }
-}
-
-const mapStateToProps = state => ({
- enableGravatar: (getGlobalSettingValue(state, 'sonar.lf.enableGravatar') || {}).value === 'true',
- gravatarServerUrl: (getGlobalSettingValue(state, 'sonar.lf.gravatarServerUrl') || {}).value
-});
-
-export default connect(mapStateToProps)(Avatar);
-
-export const unconnectedAvatar = Avatar;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { connect } from 'react-redux';
+import * as classNames from 'classnames';
+import { getGlobalSettingValue } from '../../store/rootReducer';
+
+interface Props {
+ className?: string;
+ enableGravatar: boolean;
+ gravatarServerUrl: string;
+ hash?: string;
+ name: string;
+ size: number;
+}
+
+class Avatar extends React.PureComponent<Props> {
+ renderFallback() {
+ const className = classNames(this.props.className, 'rounded');
+ const color = stringToColor(this.props.name);
+
+ let text = '';
+ const words = this.props.name.split(/\s+/).filter(word => word.length > 0);
+ if (words.length >= 2) {
+ text = words[0][0] + words[1][0];
+ } else if (this.props.name.length > 0) {
+ text = this.props.name[0];
+ }
+
+ return (
+ <div
+ className={className}
+ style={{
+ backgroundColor: color,
+ color: getTextColor(color),
+ display: 'inline-block',
+ fontSize: Math.min(this.props.size / 2, 14),
+ fontWeight: 'normal',
+ height: this.props.size,
+ lineHeight: `${this.props.size}px`,
+ textAlign: 'center',
+ verticalAlign: 'top',
+ width: this.props.size
+ }}>
+ {text.toUpperCase()}
+ </div>
+ );
+ }
+
+ render() {
+ if (!this.props.enableGravatar || !this.props.hash) {
+ return this.renderFallback();
+ }
+
+ const url = this.props.gravatarServerUrl
+ .replace('{EMAIL_MD5}', this.props.hash)
+ .replace('{SIZE}', String(this.props.size * 2));
+
+ return (
+ <img
+ className={classNames(this.props.className, 'rounded')}
+ src={url}
+ width={this.props.size}
+ height={this.props.size}
+ alt={this.props.name}
+ />
+ );
+ }
+}
+
+const mapStateToProps = (state: any) => ({
+ enableGravatar: (getGlobalSettingValue(state, 'sonar.lf.enableGravatar') || {}).value === 'true',
+ gravatarServerUrl: (getGlobalSettingValue(state, 'sonar.lf.gravatarServerUrl') || {}).value
+});
+
+export default connect(mapStateToProps)(Avatar);
+
+export const unconnectedAvatar = Avatar;
+
+/* eslint-disable no-bitwise, no-mixed-operators */
+function stringToColor(str: string) {
+ let hash = 0;
+ for (let i = 0; i < str.length; i++) {
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ let color = '#';
+ for (let i = 0; i < 3; i++) {
+ const value = (hash >> (i * 8)) & 0xff;
+ color += ('00' + value.toString(16)).substr(-2);
+ }
+ return color;
+}
+
+function getTextColor(background: string) {
+ const rgb = parseInt(background.substr(1), 16);
+ const r = (rgb >> 16) & 0xff;
+ const g = (rgb >> 8) & 0xff;
+ const b = (rgb >> 0) & 0xff;
+ const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
+ return luma > 140 ? '#222' : '#fff';
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import { shallow } from 'enzyme';
-import React from 'react';
-import { unconnectedAvatar as Avatar } from '../Avatar';
-
-const gravatarServerUrl = 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}';
-
-it.skip('should render', () => {
- const avatar = shallow(
- <Avatar
- enableGravatar={true}
- gravatarServerUrl={gravatarServerUrl}
- email="mail@example.com"
- name="Foo"
- size={20}
- />
- );
- expect(avatar).toMatchSnapshot();
-});
-
-it('should be able to render with hash only', () => {
- const avatar = shallow(
- <Avatar
- enableGravatar={true}
- gravatarServerUrl={gravatarServerUrl}
- hash="7daf6c79d4802916d83f6266e24850af"
- name="Foo"
- size={30}
- />
- );
- expect(avatar).toMatchSnapshot();
-});
-
-it('falls back to dummy avatar', () => {
- const avatar = shallow(
- <Avatar enableGravatar={false} gravatarServerUrl="" name="Foo Bar" size={30} />
- );
- expect(avatar).toMatchSnapshot();
-});
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import { unconnectedAvatar as Avatar } from '../Avatar';
+
+const gravatarServerUrl = 'http://example.com/{EMAIL_MD5}.jpg?s={SIZE}';
+
+it('should be able to render with hash only', () => {
+ const avatar = shallow(
+ <Avatar
+ enableGravatar={true}
+ gravatarServerUrl={gravatarServerUrl}
+ hash="7daf6c79d4802916d83f6266e24850af"
+ name="Foo"
+ size={30}
+ />
+ );
+ expect(avatar).toMatchSnapshot();
+});
+
+it('falls back to dummy avatar', () => {
+ const avatar = shallow(
+ <Avatar enableGravatar={false} gravatarServerUrl="" name="Foo Bar" size={30} />
+ );
+ expect(avatar).toMatchSnapshot();
+});
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`falls back to dummy avatar 1`] = `
-<div
- className="rounded"
- style={
- Object {
- "backgroundColor": "#79e189",
- "color": "#222",
- "display": "inline-block",
- "fontSize": 14,
- "fontWeight": "normal",
- "height": 30,
- "lineHeight": "30px",
- "textAlign": "center",
- "verticalAlign": "top",
- "width": 30,
- }
- }
->
- FB
-</div>
-`;
-
-exports[`should be able to render with hash only 1`] = `
-<img
- className="rounded"
- height={30}
- src="http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=60"
- width={30}
-/>
-`;
-
-exports[`should render 1`] = `
-<img
- alt="mail@example.com"
- className="rounded"
- height={20}
- src="http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=40"
- width={20}
-/>
-`;
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`falls back to dummy avatar 1`] = `
+<div
+ className="rounded"
+ style={
+ Object {
+ "backgroundColor": "#79e189",
+ "color": "#222",
+ "display": "inline-block",
+ "fontSize": 14,
+ "fontWeight": "normal",
+ "height": 30,
+ "lineHeight": "30px",
+ "textAlign": "center",
+ "verticalAlign": "top",
+ "width": 30,
+ }
+ }
+>
+ FB
+</div>
+`;
+
+exports[`should be able to render with hash only 1`] = `
+<img
+ alt="Foo"
+ className="rounded"
+ height={30}
+ src="http://example.com/7daf6c79d4802916d83f6266e24850af.jpg?s=60"
+ width={30}
+/>
+`;
const WithStore = require('../../components/shared/WithStore').default;
const Avatar = require('../../components/ui/Avatar').default;
-module.exports = function(email, name, size) {
+module.exports = function(hash, name, size) {
return new Handlebars.default.SafeString(
renderToString(
<WithStore>
- <Avatar email={email} name={name} size={size} />
+ <Avatar hash={hash} name={name} size={size} />
</WithStore>
)
);
version "3.5.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
-blueimp-md5@1.1.1:
- version "1.1.1"
- resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-1.1.1.tgz#cf84ba18285f5c8835dae8ddae5af6468ceace17"
-
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
optional string name = 2;
optional string email = 3;
repeated string permissions = 4;
+ optional string avatar = 5;
}
message OldGroup {
repeated string groups = 9;
optional Permissions permissions = 10;
optional bool showOnboardingTutorial = 11;
+ optional string avatar = 12;
message Permissions {
repeated string global = 1;