From 53e5dfee7cdca9ed8a7806858e593d3723524d23 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 27 Aug 2017 20:12:54 -0600 Subject: [PATCH] Check user permissions and metadata every CMS load. Before, if the CMS was loading user OAuth credentials from `localStorage`, then user write access would not be checked again. However, the `config.yml` repo could be changed, which would cause the user to be still logged in even if they did not have write permissions. Also, if the user had updated their metadata (avatar, etc.), the CMS would not update that either. --- src/backends/backend.js | 5 ++++- src/backends/github/implementation.js | 3 +-- src/backends/test-repo/implementation.js | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backends/backend.js b/src/backends/backend.js index 96746a0d..1d81b4d8 100644 --- a/src/backends/backend.js +++ b/src/backends/backend.js @@ -78,7 +78,10 @@ class Backend { if (this.user) { return this.user; } const stored = this.authStore && this.authStore.retrieve(); if (stored) { - return Promise.resolve(this.implementation.setUser(stored)).then(() => stored); + return Promise.resolve(this.implementation.setUser(stored)).then((user) => { + this.authStore.store(user); + return user; + }); } return Promise.resolve(null); } diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index f071d021..c7846677 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -24,8 +24,7 @@ export default class GitHub { } setUser(user) { - this.token = user.token; - this.api = new API({ token: this.token, branch: this.branch, repo: this.repo }); + return this.authenticate(user); } authenticate(state) { diff --git a/src/backends/test-repo/implementation.js b/src/backends/test-repo/implementation.js index c7cc22c7..07749dd6 100644 --- a/src/backends/test-repo/implementation.js +++ b/src/backends/test-repo/implementation.js @@ -26,12 +26,14 @@ export default class TestRepo { this.config = config; } - setUser() {} - authComponent() { return AuthenticationPage; } + setUser(user) { + return this.authenticate(user); + } + authenticate(state) { return Promise.resolve({ email: state.email, name: nameFromEmail(state.email) }); }