@@ -15,7 +15,6 @@ import MemberListStore from 'app/stores/memberListStore';
15
15
import MissingProjectMembership from 'app/components/missingProjectMembership' ;
16
16
import OrganizationState from 'app/mixins/organizationState' ;
17
17
import ProjectsStore from 'app/stores/projectsStore' ;
18
- import recreateRoute from 'app/utils/recreateRoute' ;
19
18
import SentryTypes from 'app/sentryTypes' ;
20
19
import withProjects from 'app/utils/withProjects' ;
21
20
@@ -138,6 +137,7 @@ const ProjectContext = createReactClass({
138
137
let { orgId, projectId, location, skipReload} = this . props ;
139
138
// we fetch core access/information from the global organization data
140
139
let activeProject = this . identifyProject ( ) ;
140
+ let hasAccess = activeProject && activeProject . hasAccess ;
141
141
142
142
this . setState ( state => ( {
143
143
// if `skipReload` is true, then don't change loading state
@@ -146,53 +146,66 @@ const ProjectContext = createReactClass({
146
146
project : activeProject ,
147
147
} ) ) ;
148
148
149
- setActiveProject ( null ) ;
150
- const projectRequest = this . api . requestPromise ( `/projects/${ orgId } /${ projectId } /` ) ;
151
-
152
- const environmentRequest = this . api . requestPromise ( this . getEnvironmentListEndpoint ( ) ) ;
153
-
154
- Promise . all ( [ projectRequest , environmentRequest ] ) . then (
155
- ( [ project , envs ] ) => {
156
- this . setState ( {
157
- loading : false ,
158
- project,
159
- error : false ,
160
- errorType : null ,
161
- } ) ;
162
-
163
- // assuming here that this means the project is considered the active project
164
- setActiveProject ( project ) ;
165
-
166
- // If an environment is specified in the query string, load it instead of default
167
- const queryEnv = location . query . environment ;
168
- // The default environment cannot be "" (No Environment)
169
- const { defaultEnvironment} = project ;
170
- const envName = typeof queryEnv === 'undefined' ? defaultEnvironment : queryEnv ;
171
- loadEnvironments ( envs , envName ) ;
172
-
173
- // TODO(dcramer): move member list to organization level
174
- this . api . request ( this . getMemberListEndpoint ( ) , {
175
- success : data => {
176
- MemberListStore . loadInitialData ( data . filter ( m => m . user ) . map ( m => m . user ) ) ;
177
- } ,
178
- } ) ;
179
- } ,
180
- resp => {
181
- let errorType = ERROR_TYPES . UNKNOWN ;
182
-
183
- if ( resp . status === 404 ) {
184
- errorType = ERROR_TYPES . PROJECT_NOT_FOUND ;
185
- } else if ( activeProject && ! activeProject . isMember ) {
186
- errorType = ERROR_TYPES . MISSING_MEMBERSHIP ;
149
+ if ( activeProject && hasAccess ) {
150
+ setActiveProject ( null ) ;
151
+ const projectRequest = this . api . requestPromise ( `/projects/${ orgId } /${ projectId } /` ) ;
152
+
153
+ const environmentRequest = this . api . requestPromise (
154
+ this . getEnvironmentListEndpoint ( )
155
+ ) ;
156
+
157
+ Promise . all ( [ projectRequest , environmentRequest ] ) . then (
158
+ ( [ project , envs ] ) => {
159
+ this . setState ( {
160
+ loading : false ,
161
+ project,
162
+ error : false ,
163
+ errorType : null ,
164
+ } ) ;
165
+
166
+ // assuming here that this means the project is considered the active project
167
+ setActiveProject ( project ) ;
168
+
169
+ // If an environment is specified in the query string, load it instead of default
170
+ const queryEnv = location . query . environment ;
171
+ // The default environment cannot be "" (No Environment)
172
+ const { defaultEnvironment} = project ;
173
+ const envName = typeof queryEnv === 'undefined' ? defaultEnvironment : queryEnv ;
174
+ loadEnvironments ( envs , envName ) ;
175
+ } ,
176
+ ( ) => {
177
+ this . setState ( {
178
+ loading : false ,
179
+ error : false ,
180
+ errorType : ERROR_TYPES . UNKNOWN ,
181
+ } ) ;
187
182
}
183
+ ) ;
188
184
189
- this . setState ( {
190
- loading : false ,
191
- error : true ,
192
- errorType,
193
- } ) ;
194
- }
195
- ) ;
185
+ // TODO(dcramer): move member list to organization level
186
+ this . api . request ( this . getMemberListEndpoint ( ) , {
187
+ success : data => {
188
+ MemberListStore . loadInitialData ( data . filter ( m => m . user ) . map ( m => m . user ) ) ;
189
+ } ,
190
+ } ) ;
191
+ } else if ( activeProject && ! activeProject . isMember ) {
192
+ this . setState ( {
193
+ loading : false ,
194
+ error : true ,
195
+ errorType : ERROR_TYPES . MISSING_MEMBERSHIP ,
196
+ } ) ;
197
+ } else {
198
+ // The request is a 404 or other error
199
+ this . api . request ( `/projects/${ orgId } /${ projectId } /` , {
200
+ error : ( ) => {
201
+ this . setState ( {
202
+ loading : false ,
203
+ error : true ,
204
+ errorType : ERROR_TYPES . PROJECT_NOT_FOUND ,
205
+ } ) ;
206
+ } ,
207
+ } ) ;
208
+ }
196
209
} ,
197
210
198
211
getEnvironmentListEndpoint ( ) {
0 commit comments