Skip to content

Commit d73a721

Browse files
author
vikasrohit
authored
Merge pull request #1488 from appirio-tech/feature/admin-functionality-update-01
Feature/admin functionality update 01
2 parents 9244be4 + 1bc5e36 commit d73a721

File tree

10 files changed

+42
-18
lines changed

10 files changed

+42
-18
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compile:
1919

2020
deployment:
2121
development:
22-
branch: [dev, 'feature/performance-testing']
22+
branch: dev
2323
owner: appirio-tech
2424
commands:
2525
- ./deploy.sh DEV

src/actions/loadUser.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import _ from 'lodash'
2-
import { ACCOUNTS_APP_CONNECTOR_URL, LOAD_USER_SUCCESS, LOAD_USER_FAILURE, ROLE_ADMINISTRATOR, ROLE_CONNECT_COPILOT, ROLE_TOPCODER_USER, ROLE_CONNECT_MANAGER } from '../config/constants'
2+
import {
3+
ACCOUNTS_APP_CONNECTOR_URL,
4+
LOAD_USER_SUCCESS,
5+
LOAD_USER_FAILURE,
6+
ROLE_ADMINISTRATOR,
7+
ROLE_CONNECT_COPILOT,
8+
ROLE_TOPCODER_USER,
9+
ROLE_CONNECT_MANAGER,
10+
ROLE_CONNECT_ADMIN
11+
} from '../config/constants'
312
import { getFreshToken, configureConnector, decodeToken } from 'tc-accounts'
413
import { getUserProfile } from '../api/users'
514
import { EventTypes } from 'redux-segment'
@@ -46,6 +55,8 @@ export function loadUserSuccess(dispatch, token) {
4655
let userRole
4756
if (_.indexOf(currentUser.roles, ROLE_ADMINISTRATOR) > -1) {
4857
userRole = ROLE_ADMINISTRATOR
58+
} else if (_.indexOf(currentUser.roles, ROLE_CONNECT_ADMIN) > -1) {
59+
userRole = ROLE_CONNECT_ADMIN
4960
} else if (_.indexOf(currentUser.roles, ROLE_CONNECT_MANAGER) > -1) {
5061
userRole = ROLE_CONNECT_MANAGER
5162
} else if (_.indexOf(currentUser.roles, ROLE_CONNECT_COPILOT) > -1) {

src/components/TeamManagement/MemberRow.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ActionBtn = (props) => {
2020
)
2121
}
2222

23-
const MemberRow = ({ member, currentMember, onMemberDelete, onChangeOwner }) => {
23+
const MemberRow = ({ member, currentMember, currentUser, onMemberDelete, onChangeOwner }) => {
2424
let title
2525
// rendered member
2626
const isOwner = member.isPrimary && member.isCustomer
@@ -44,21 +44,24 @@ const MemberRow = ({ member, currentMember, onMemberDelete, onChangeOwner }) =>
4444
if (!isCurrentOwner && !member.isCopilot) {
4545
buttons.push(<ActionBtn key={0} type="leave" title="Leave Project" onClick={onDelete} />)
4646
}
47-
} else if (currentMember) {
47+
} else if (currentMember || currentUser.isAdmin) {
4848
// owner can remove only customers
4949
if (isCurrentOwner && member.isCustomer) {
5050
buttons.push(<ActionBtn key={1} type="user-remove" title="Remove team member from project" onClick={onDelete} />)
5151
}
5252

5353
// manager can remove all except owner
54-
if (currentMember.isManager && !isOwner) {
54+
if ((currentMember && currentMember.isManager) || currentUser.isAdmin) {
5555
let tooltip = 'Remove team member from project'
5656
if (member.isCopilot) {
5757
tooltip = 'Remove copilot from project'
5858
}
5959
if (member.isManager) {
6060
tooltip = 'Remove manager from project'
6161
}
62+
if (member.isCustomer && isOwner) {
63+
tooltip = 'Remove owner from project'
64+
}
6265
buttons.push(<ActionBtn key={2} type="user-remove" title={tooltip} onClick={onDelete} />)
6366
}
6467

src/components/TeamManagement/TeamManagement.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const TeamManagement = (props) => {
6161
return (
6262
<div className="team-management">
6363
<Panel className={cn({'modal-active': modalActive})}>
64-
{currentMember && <Panel.AddBtn onClick={() => onToggleAddTeamMember(true)}>Add Team Member</Panel.AddBtn>}
64+
{(currentMember || currentUser.isAdmin) && <Panel.AddBtn onClick={() => onToggleAddTeamMember(true)}>Add Team Member</Panel.AddBtn>}
6565

6666
{modalActive && <div className="modal-overlay" />}
6767
<Panel.Title>
@@ -114,7 +114,7 @@ const TeamManagement = (props) => {
114114
})}
115115

116116
{canJoin && <Join {...props} isCopilot={currentUser.isCopilot} owner={owner} />}
117-
{currentMember && <AddTeamMember {...props} owner={owner} />}
117+
{(currentMember || currentUser.isAdmin) && <AddTeamMember {...props} owner={owner} />}
118118

119119
{ showNewMemberConfirmation && <NewMemberConfirmModal onConfirm={ _onAddNewMember } onCancel={ _onAddMemberCancel } />}
120120
</Panel>

src/components/TopBar/TopBarContainer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ROLE_CONNECT_COPILOT,
1111
ROLE_CONNECT_MANAGER,
1212
ROLE_ADMINISTRATOR,
13+
ROLE_CONNECT_ADMIN,
1314
DOMAIN
1415
} from '../../config/constants'
1516
require('./TopBarContainer.scss')
@@ -122,7 +123,7 @@ class TopBarContainer extends React.Component {
122123

123124
const mapStateToProps = ({ loadUser }) => {
124125
let isPowerUser = false
125-
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR]
126+
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
126127
if (loadUser.user) {
127128
isPowerUser = loadUser.user.roles.some((role) => roles.indexOf(role) !== -1)
128129
}

src/config/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export const EVENT_ROUTE_CHANGE = 'event.route_change'
217217
export const ROLE_TOPCODER_USER = 'Topcoder User'
218218
export const ROLE_CONNECT_COPILOT = 'Connect Copilot'
219219
export const ROLE_CONNECT_MANAGER = 'Connect Manager'
220+
export const ROLE_CONNECT_ADMIN = 'Connect Admin'
220221
export const ROLE_ADMINISTRATOR = 'administrator'
221222

222223
// FIXME .. remove defaults

src/projects/actions/loadProjects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
PROJECT_SEARCH, GET_PROJECTS, PROJECT_STATUS, PROJECT_STATUS_CANCELLED,
44
SET_SEARCH_TERM, GET_PROJECTS_SEARCH_CRITERIA,
55
CLEAR_PROJECT_SUGGESTIONS_SEARCH, PROJECT_SUGGESTIONS_SEARCH_SUCCESS,
6-
ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR
6+
ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN
77
} from '../../config/constants'
88
import { getProjects } from '../../api/projects'
99
import { loadMembers } from '../../actions/members'
@@ -23,7 +23,7 @@ const getProjectsWithMembers = (dispatch, getState, criteria, pageNum) => {
2323
let isPowerUser = false
2424
const loadUser = getState().loadUser
2525
// power user roles
26-
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR]
26+
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
2727
if (loadUser.user) {
2828
// determine if user is a power user
2929
isPowerUser = loadUser.user.roles.some((role) => roles.indexOf(role) !== -1)

src/projects/detail/ProjectDetail.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { renderComponent, branch, compose, withProps } from 'recompose'
77
import { loadProjectDashboard } from '../actions/projectDashboard'
88
import {
99
LOAD_PROJECT_FAILURE, PROJECT_ROLE_CUSTOMER, PROJECT_ROLE_OWNER,
10-
ROLE_ADMINISTRATOR
10+
ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN
1111
} from '../../config/constants'
1212
import spinnerWhileLoading from '../../components/LoadingSpinner'
1313
import CoderBot from '../../components/CoderBot/CoderBot'
@@ -71,7 +71,7 @@ class ProjectDetail extends Component {
7171

7272
render() {
7373
const currentMemberRole = this.getProjectRoleForCurrentUser(this.props)
74-
const powerRoles = [ROLE_ADMINISTRATOR]
74+
const powerRoles = [ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
7575
const isSuperUser = this.props.currentUserRoles.some((role) => powerRoles.indexOf(role) !== -1)
7676
return (
7777
<EnhancedProjectDetailView

src/projects/detail/containers/TeamManagementContainer.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { connect } from 'react-redux'
33
import { withRouter } from 'react-router-dom'
44
import _ from 'lodash'
55
import {
6-
ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR,
7-
PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_CUSTOMER, AUTOCOMPLETE_TRIGGER_LENGTH
6+
ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN,
7+
PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_CUSTOMER,
8+
AUTOCOMPLETE_TRIGGER_LENGTH
89
} from '../../../config/constants'
910
import TeamManagement from '../../../components/TeamManagement/TeamManagement'
1011
import { addProjectMember, updateProjectMember, removeProjectMember,
@@ -221,12 +222,14 @@ class TeamManagementContainer extends Component {
221222
}
222223

223224
const mapStateToProps = ({ loadUser, members }) => {
224-
const powerUserRoles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR]
225-
const managerRoles = [ ROLE_ADMINISTRATOR, ROLE_CONNECT_MANAGER ]
225+
const adminRoles = [ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
226+
const powerUserRoles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
227+
const managerRoles = [ ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN, ROLE_CONNECT_MANAGER ]
226228
return {
227229
currentUser: {
228230
userId: parseInt(loadUser.user.id),
229231
isCopilot: _.indexOf(loadUser.user.roles, ROLE_CONNECT_COPILOT) > -1,
232+
isAdmin: _.intersection(loadUser.user.roles, adminRoles).length > 0,
230233
isManager: loadUser.user.roles.some((role) => managerRoles.indexOf(role) !== -1),
231234
isCustomer: !loadUser.user.roles.some((role) => powerUserRoles.indexOf(role) !== -1)
232235
},

src/projects/list/components/Projects/Projects.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import ProjectsCardView from './ProjectsCardView'
99
import { loadProjects } from '../../../actions/loadProjects'
1010
import _ from 'lodash'
1111
import querystring from 'query-string'
12-
import { ROLE_CONNECT_MANAGER, ROLE_CONNECT_COPILOT, ROLE_ADMINISTRATOR } from '../../../../config/constants'
12+
import {
13+
ROLE_CONNECT_MANAGER,
14+
ROLE_CONNECT_COPILOT,
15+
ROLE_ADMINISTRATOR,
16+
ROLE_CONNECT_ADMIN
17+
} from '../../../../config/constants'
1318

1419
// This handles showing a spinner while the state is being loaded async
1520
import spinnerWhileLoading from '../../../../components/LoadingSpinner'
@@ -172,7 +177,7 @@ class Projects extends Component {
172177

173178
const mapStateToProps = ({ projectSearch, members, loadUser }) => {
174179
let isPowerUser = false
175-
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR]
180+
const roles = [ROLE_CONNECT_COPILOT, ROLE_CONNECT_MANAGER, ROLE_ADMINISTRATOR, ROLE_CONNECT_ADMIN]
176181
if (loadUser.user) {
177182
isPowerUser = loadUser.user.roles.some((role) => roles.indexOf(role) !== -1)
178183
}

0 commit comments

Comments
 (0)