Skip to content

Commit ccc1e4c

Browse files
committed
Allow admins to see all projects in the projects dropdown, regardless of their membership
1 parent 8c95588 commit ccc1e4c

File tree

8 files changed

+81
-244
lines changed

8 files changed

+81
-244
lines changed

src/components/Sidebar/Sidebar.module.scss

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/components/Sidebar/index.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/config/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export const LOAD_PROJECTS_PENDING = 'LOAD_PROJECTS_PENDING'
5757
export const LOAD_PROJECTS_FAILURE = 'LOAD_PROJECTS_FAILURE'
5858
export const UNLOAD_PROJECTS_SUCCESS = 'UNLOAD_PROJECTS_SUCCESS'
5959

60+
export const LOAD_ALL_USER_PROJECTS_SUCCESS = 'LOAD_ALL_USER_PROJECTS_SUCCESS'
61+
export const LOAD_ALL_USER_PROJECTS_PENDING = 'LOAD_ALL_USER_PROJECTS_PENDING'
62+
export const LOAD_ALL_USER_PROJECTS_FAILURE = 'LOAD_ALL_USER_PROJECTS_FAILURE'
63+
6064
// project billingAccount
6165
export const LOAD_PROJECT_BILLING_ACCOUNT = 'LOAD_PROJECT_BILLING_ACCOUNT'
6266
export const LOAD_PROJECT_BILLING_ACCOUNT_PENDING = 'LOAD_PROJECT_BILLING_ACCOUNT_PENDING'

src/containers/Sidebar/index.js

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/containers/Tab/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ class TabContainer extends Component {
1717
searchProjectName: '',
1818
currentTab: 1
1919
}
20-
this.updateProjectName = this.updateProjectName.bind(this)
2120
this.onTabChange = this.onTabChange.bind(this)
2221
}
2322

2423
componentDidMount () {
25-
const { projectId, activeProjectId, isLoading, selfService } = this.props
26-
if (!projectId && activeProjectId === -1 && !isLoading && !selfService) {
24+
const {
25+
projectId,
26+
activeProjectId,
27+
isLoading,
28+
selfService,
29+
history
30+
} = this.props
31+
if (
32+
!projectId &&
33+
activeProjectId === -1 &&
34+
!isLoading &&
35+
!selfService &&
36+
// do not fetch projects for users page
37+
history.location.pathname !== '/users'
38+
) {
2739
this.props.loadProjects()
2840
}
2941

@@ -46,15 +58,22 @@ class TabContainer extends Component {
4658
} else {
4759
this.setState({ currentTab: 0 })
4860
}
61+
if (
62+
isLoading ||
63+
// do not fetch projects for users page
64+
nextProps.history.location.pathname === '/users'
65+
) {
66+
return
67+
}
4968
// if we're viewing a specific project,
5069
// or we're viewing the self serve page,
5170
// or if the project is already loading,
5271
// don't load the projects
53-
if (!!projectId || selfService || isLoading) {
72+
if (!!projectId || selfService) {
5473
// if we're not in the middle of loading,
5574
// and we have projects to unload,
5675
// unload them
57-
if (!isLoading && !!projects && !!projects.length) {
76+
if (!!projects && !!projects.length) {
5877
this.props.unloadProjects()
5978
}
6079

@@ -71,11 +90,6 @@ class TabContainer extends Component {
7190
this.props.loadProjects()
7291
}
7392

74-
updateProjectName (val) {
75-
this.setState({ searchProjectName: val })
76-
this.props.loadProjects(val)
77-
}
78-
7993
onTabChange (tab) {
8094
const { history, resetSidebarActiveParams } = this.props
8195
if (tab === 1) {

src/containers/Users/index.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import PT from 'prop-types'
55
import UsersComponent from '../../components/Users'
66
import { PROJECT_ROLES } from '../../config/constants'
77
import { fetchProjectById } from '../../services/projects'
8+
import { checkAdmin } from '../../util/tc'
9+
10+
import {
11+
loadAllUserProjects
12+
} from '../../actions/users'
813

914
class Users extends Component {
1015
constructor (props) {
@@ -21,6 +26,11 @@ class Users extends Component {
2126
}
2227

2328
componentDidMount () {
29+
const { token, isLoading, loadAllUserProjects } = this.props
30+
if (!isLoading) {
31+
const isAdmin = checkAdmin(token)
32+
loadAllUserProjects(isAdmin)
33+
}
2434
}
2535

2636
isEditable () {
@@ -118,18 +128,27 @@ class Users extends Component {
118128
}
119129
}
120130

121-
const mapStateToProps = ({ sidebar, auth }) => {
131+
const mapStateToProps = ({ users, auth }) => {
122132
return {
123-
projects: sidebar.projects,
133+
projects: users.allUserProjects,
134+
isLoading: users.isLoadingAllUserProjects,
124135
auth,
125-
loggedInUser: auth.user
136+
loggedInUser: auth.user,
137+
token: auth.token
126138
}
127139
}
128140

129141
Users.propTypes = {
130142
projects: PT.arrayOf(PT.object),
131143
auth: PT.object,
132-
loggedInUser: PT.object
144+
loggedInUser: PT.object,
145+
token: PT.string,
146+
isLoading: PT.bool,
147+
loadAllUserProjects: PT.func.isRequired
148+
}
149+
150+
const mapDispatchToProps = {
151+
loadAllUserProjects
133152
}
134153

135-
export default connect(mapStateToProps)(Users)
154+
export default connect(mapStateToProps, mapDispatchToProps)(Users)

src/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import projects from './projects'
99
import challengeSubmissions from './challengeSubmissions'
1010
import sidebar from './sidebar'
1111
import members from './members'
12+
import users from './users'
1213

1314
export default combineReducers({
1415
auth,
@@ -17,5 +18,6 @@ export default combineReducers({
1718
sidebar,
1819
toastr: toastrReducer,
1920
projects,
20-
members
21+
members,
22+
users
2123
})

0 commit comments

Comments
 (0)