Skip to content

Commit

Permalink
feat: Github connector Connector settings - MEED-2195 - Meeds-io/MIPs#64
Browse files Browse the repository at this point in the history


This PR will make sure to validate users' GitHub accounts before saving using OauthService
  • Loading branch information
AzmiTouil committed Jun 19, 2023
1 parent b56fbcf commit c6a3af3
Show file tree
Hide file tree
Showing 20 changed files with 1,006 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,7 @@ gamification.achivementRecurrence.weeklyTooltip=Do it once per week
gamification.achivementRecurrence.monthly=Monthly
gamification.achivementRecurrence.monthlyTitle=Monthly
gamification.achivementRecurrence.monthlyTooltip=Do it once per month

gamification.connectors.label.connectors=Gamified third-party Apps
gamification.connectors.label.connect=Connect
gamification.connectors.label.disconnect=Disconnect
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<type>io.meeds.gamification.rest.GamificationRestEndpoint</type>
</component>

<component>
<type>io.meeds.gamification.rest.ConnectorRest</type>
</component>

<component>
<key>io.meeds.gamification.service.ConnectorService</key>
<type>io.meeds.gamification.service.impl.ConnectorServiceImpl</type>
</component>

<component>
<key>io.meeds.gamification.service.AnnouncementService</key>
<type>io.meeds.gamification.service.impl.AnnouncementServiceImpl</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,55 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</component-plugin>
</external-component-plugins>

<external-component-plugins>
<target-component>org.exoplatform.commons.addons.AddOnService</target-component>
<component-plugin>
<name>addPlugin</name>
<set-method>addPlugin</set-method>
<type>org.exoplatform.commons.addons.AddOnPluginImpl</type>
<description></description>
<init-params>
<value-param>
<name>priority</name>
<value>3</value>
</value-param>
<value-param>
<name>containerName</name>
<value>settings-bottom-container</value>
</value-param>
<object-param>
<name>gamification-connectors-settings</name>
<description></description>
<object type="org.exoplatform.commons.addons.PortletModel">
<field name="contentId">
<string>gamification-portlets/ConnectorsSettings</string>
</field>
<field name="permissions">
<collection type="java.util.ArrayList">
<value>
<string>*:/platform/users</string>
</value>
<value>
<string>*:/platform/externals</string>
</value>
</collection>
</field>
<field name="title">
<string>Gamification Connectors Settings</string>
</field>
<field name="showInfoBar">
<boolean>false</boolean>
</field>
<field name="showApplicationState">
<boolean>false</boolean>
</field>
<field name="showApplicationMode">
<boolean>false</boolean>
</field>
</object>
</object-param>
</init-params>
</component-plugin>
</external-component-plugins>

</configuration>
29 changes: 29 additions & 0 deletions portlets/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,35 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</module>
</portlet>

<portlet>
<name>ConnectorsSettings</name>
<module>
<load-group>gamification-connectors</load-group>
<script>
<minify>false</minify>
<path>/js/connectorsSettings.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>gamificationCommon</module>
</depends>
</module>
</portlet>

<module>
<name>EngagementCenterActivityStreamExtension</name>
<load-group>ActivityStreamGRP</load-group>
Expand Down
20 changes: 20 additions & 0 deletions portlets/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,24 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</portlet-info>
</portlet>

<portlet>
<portlet-name>ConnectorsSettings</portlet-name>
<display-name xml:lang="EN">Gamification Connectors Settings</display-name>
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/html/connectorsSettings.html</value>
</init-param>
<expiration-cache>-1</expiration-cache>
<cache-scope>PUBLIC</cache-scope>
<supports>
<mime-type>text/html</mime-type>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Gamification Connectors Settings</title>
<keywords>Gamification Connectors Settings</keywords>
</portlet-info>
</portlet>

</portlet-app>
9 changes: 9 additions & 0 deletions portlets/src/main/webapp/html/connectorsSettings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="VuetifyApp">
<div data-app="true"
class="v-application v-application--is-ltr"
id="connectorsSettingsApp">
<script type="text/javascript">
require(['PORTLET/gamification-portlets/ConnectorsSettings'], app => app.init());
</script>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2020 - 2023 Meeds Association
[email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<template>
<v-app v-if="displayed">
<v-card class="my-3 border-radius" flat>
<v-list two-line>
<v-list-item>
<v-list-item-content>
<v-list-item-title class="title text-color">
{{ $t('gamification.connectors.label.connectors') }}
</v-list-item-title>
<v-list-item-subtitle class="my-3 text-sub-title font-italic">
<gamification-connectors-status :connected-connectors="enabledConnectors" />
</v-list-item-subtitle>
</v-list-item-content>
<gamification-connector
:connectors="connectors"
@connectors-loaded="connectors = $event" />
</v-list-item>
</v-list>
</v-card>
</v-app>
</template>

<script>
export default {
data: () => ({
displayed: true,
connectors: [],
enabledConnectors: [],
}),
watch: {
connectors: {
immediate: true,
deep: true,
handler: function() {
if (this.connectors && this.connectors.length) {
this.enabledConnectors = this.connectors && this.connectors.filter(connector => connector.enabled) || [];
}
}
},
},
created() {
document.addEventListener('hideSettingsApps', (event) => {
if (event && event.detail && this.id !== event.detail) {
this.displayed = false;
}
});
document.addEventListener('showSettingsApps', () => this.displayed = true);
},
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2020 - 2023 Meeds Association
[email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<script>
export default {
props: {
connectors: {
type: Object,
default: () => null,
},
},
data() {
return {
loading: false,
};
},
created() {
this.refreshConnectorsList();
document.addEventListener('gamification-connectors-refresh', this.refreshConnectorsList);
this.$root.$on('gamification-connector-connect', this.addAccount);
this.$root.$on('gamification-connector-disconnect', this.removeAccount);
},
mounted() {
this.refreshConnectorsList();
},
methods: {
refreshConnectorsList() {
// Get list of connectors from extensionRegistry
const connectors = extensionRegistry.loadExtensions('gamification', 'connectors') || [];
// Check connectors status from store
this.$connectorService.getConnectors().then(connectorsList => {
if (connectorsList && connectorsList.length) {
connectors.forEach(connector => {
const connectorObj = connectorsList.find(connectorSettings => connectorSettings.name === connector.name);
connector.apiKey = connectorObj && connectorObj.apiKey || '';
connector.redirectURL = connectorObj && connectorObj.redirectURL || '';
connector.enabled = connectorObj != null;
connector.isSignedIn = connectorObj.connected;
connector.identifier = connectorObj.identifier || '';
connector.user = eXo.env.portal.userName;
});
} else {
connectors.forEach(connector => (connector.enabled = false));
}
});
this.$emit('connectors-loaded', connectors);
},
addAccount(connector) {
this.$set(connector, 'loading', true);
const popup = connector.openOauthPopup(connector);
// Listen for changes in the popup window's URL
const popupInterval = setInterval(() => {
if (popup.location.href.startsWith(connector.redirectURL)) {
clearInterval(popupInterval);
this.handleCallback(popup.location.href, connector).then(() => {
connector.loading = false;
}).finally(() => popup.close());
}
}, 500);
},
handleCallback(callbackUrl, connector) {
const url = new URL(callbackUrl);
const searchParams = new URLSearchParams(url.search);
const code = searchParams.get('code');
const connectorLoginRequest = {
accessToken: code,
connectorName: connector.name
};
return this.$connectorService.saveUserConnector(connectorLoginRequest)
.then(githubIdentifier => {
connector.user = githubIdentifier || null;
document.dispatchEvent(new CustomEvent('gamification-connectors-refresh'));
});
},
removeAccount(connector) {
if (connector.isSignedIn) {
return this.$connectorService.removeUserConnector(connector).then(() => {
this.$set(connector, 'isSignedIn', false);
this.$set(connector, 'user', null);
this.$root.$emit('gamification-connectors-refresh');
})
.finally(() => {
this.$set(connector, 'loading', false);
});
}
},
},
};
</script>
Loading

0 comments on commit c6a3af3

Please sign in to comment.