Преглед на файлове

Merge pull request #16 from george-vrancianu/corweb-24

Fixes "Malformed request url" issue CORWEB-24
Alessandro Pilotti преди 8 години
родител
ревизия
138379b5b0
променени са 3 файла, в които са добавени 14 реда и са изтрити 3 реда
  1. 5 2
      src/actions/MigrationActions/MigrationActions.js
  2. 1 1
      src/components/ApiCaller/ApiCaller.js
  3. 8 0
      src/stores/UserStore/UserStore.js

+ 5 - 2
src/actions/MigrationActions/MigrationActions.js

@@ -52,7 +52,8 @@ MigrationActions.loadMigrations.listen(() => {
 
 
 MigrationActions.loadMigrations.shouldEmit = () => {
 MigrationActions.loadMigrations.shouldEmit = () => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
-  return typeof projectId !== "undefined";
+  let scoped = Reflux.GlobalState.userStore.currentUser.scoped
+  return typeof projectId !== "undefined" && scoped
 }
 }
 
 
 MigrationActions.loadReplicas.listen(() => {
 MigrationActions.loadReplicas.listen(() => {
@@ -67,7 +68,9 @@ MigrationActions.loadReplicas.listen(() => {
 
 
 MigrationActions.loadReplicas.shouldEmit = () => {
 MigrationActions.loadReplicas.shouldEmit = () => {
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
   let projectId = Reflux.GlobalState.userStore.currentUser.project.id
-  return typeof projectId !== "undefined";
+
+  let scoped = Reflux.GlobalState.userStore.currentUser.scoped
+  return typeof projectId !== "undefined" && scoped
 }
 }
 
 
 MigrationActions.loadMigration.listen((migration) => {
 MigrationActions.loadMigration.listen((migration) => {

+ 1 - 1
src/components/ApiCaller/ApiCaller.js

@@ -87,7 +87,7 @@ class ApiCaller {
           }
           }
           if (result.status == 401) {
           if (result.status == 401) {
             this.resetHeaders()
             this.resetHeaders()
-            Location.push("/login")
+            window.location.href = "/"
           }
           }
           reject({ status: request.status });
           reject({ status: request.status });
         }
         }

+ 8 - 0
src/stores/UserStore/UserStore.js

@@ -29,6 +29,7 @@ class UserStore extends Reflux.Store
 {
 {
   user = {
   user = {
     id: null,
     id: null,
+    scoped: false,
     name: "-",
     name: "-",
     email: "-",
     email: "-",
     created: new Date(),
     created: new Date(),
@@ -80,6 +81,12 @@ class UserStore extends Reflux.Store
     })
     })
   }
   }
 
 
+  onLoginScope() {
+    let currentUser = this.state.currentUser
+    currentUser.scoped = false
+    this.setState({ currentUser: currentUser })
+  }
+
   onLoginScopeSuccess(response) {
   onLoginScopeSuccess(response) {
     this.setState({ loadingState: false })
     this.setState({ loadingState: false })
 
 
@@ -88,6 +95,7 @@ class UserStore extends Reflux.Store
     currentUser.name = response.data.token.user.name
     currentUser.name = response.data.token.user.name
     currentUser.token = response.headers['X-Subject-Token'] || response.headers['x-subject-token']
     currentUser.token = response.headers['X-Subject-Token'] || response.headers['x-subject-token']
     currentUser.project = response.data.token.project
     currentUser.project = response.data.token.project
+    currentUser.scoped = true
 
 
     cookie.save('token', currentUser.token, { path: "/", expires: moment().add(1, 'hour').toDate() })
     cookie.save('token', currentUser.token, { path: "/", expires: moment().add(1, 'hour').toDate() })
     cookie.save('projectId', currentUser.project.id, { path: "/", expires: moment().add(1, 'months').toDate() })
     cookie.save('projectId', currentUser.project.id, { path: "/", expires: moment().add(1, 'months').toDate() })