From 5bc3cea6fe4a909735753692d0c4cd960e8ab516 Mon Sep 17 00:00:00 2001
From: enahum <nahumhbl@gmail.com>
Date: Wed, 3 Aug 2016 12:19:27 -0500
Subject: PLT-3484 OAuth2 Service Provider (#3632)

* PLT-3484 OAuth2 Service Provider

* PM text review for OAuth 2.0 Service Provider

* PLT-3484 OAuth2 Service Provider UI tweaks (#3668)

* Tweaks to help text

* Pushing OAuth improvements (#3680)

* Re-arrange System Console for OAuth 2.0 Provider
---
 webapp/stores/integration_store.jsx | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

(limited to 'webapp/stores/integration_store.jsx')

diff --git a/webapp/stores/integration_store.jsx b/webapp/stores/integration_store.jsx
index 454e6290b..a23b9d206 100644
--- a/webapp/stores/integration_store.jsx
+++ b/webapp/stores/integration_store.jsx
@@ -20,6 +20,8 @@ class IntegrationStore extends EventEmitter {
         this.outgoingWebhooks = new Map();
 
         this.commands = new Map();
+
+        this.oauthApps = new Map();
     }
 
     addChangeListener(callback) {
@@ -149,6 +151,35 @@ class IntegrationStore extends EventEmitter {
         this.setCommands(teamId, commands);
     }
 
+    hasReceivedOAuthApps(userId) {
+        return this.oauthApps.has(userId);
+    }
+
+    getOAuthApps(userId) {
+        return this.oauthApps.get(userId) || [];
+    }
+
+    setOAuthApps(userId, oauthApps) {
+        this.oauthApps.set(userId, oauthApps);
+    }
+
+    addOAuthApp(oauthApp) {
+        const userId = oauthApp.creator_id;
+        const oauthApps = this.getOAuthApps(userId);
+
+        oauthApps.push(oauthApp);
+
+        this.setOAuthApps(userId, oauthApps);
+    }
+
+    removeOAuthApp(userId, id) {
+        let apps = this.getOAuthApps(userId);
+
+        apps = apps.filter((app) => app.id !== id);
+
+        this.setOAuthApps(userId, apps);
+    }
+
     handleEventPayload(payload) {
         const action = payload.action;
 
@@ -197,6 +228,18 @@ class IntegrationStore extends EventEmitter {
             this.removeCommand(action.teamId, action.id);
             this.emitChange();
             break;
+        case ActionTypes.RECEIVED_OAUTHAPPS:
+            this.setOAuthApps(action.userId, action.oauthApps);
+            this.emitChange();
+            break;
+        case ActionTypes.RECEIVED_OAUTHAPP:
+            this.addOAuthApp(action.oauthApp);
+            this.emitChange();
+            break;
+        case ActionTypes.REMOVED_OAUTHAPP:
+            this.removeOAuthApp(action.userId, action.id);
+            this.emitChange();
+            break;
         }
     }
 }
-- 
cgit v1.2.3-1-g7c22

