Skip to content

Commit

Permalink
Merge PWA - Meeds-io/MIPs#134 (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored Aug 22, 2024
2 parents 5bb760b + c9f8dde commit 236f5fe
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ private WalletUtils() {

public static final String AVATAR = "avatar";

public static final String SENDER_ID = "senderIdentityId";

public static final String SENDER = "sender";

public static final String USER = "userFullname";
Expand All @@ -283,6 +285,8 @@ private WalletUtils() {

public static final String RECEIVER = "receiver";

public static final String RECEIVER_ID = "receiverIdentityId";

public static final String RECEIVER_URL = "receiverUrl";

public static final String FUNDS_ACCEPT_URL = "fundsAcceptUrl";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
*
* 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.
*/
package io.meeds.wallet.permlink.plugin;

import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.services.security.Identity;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.wallet.model.Wallet;
import org.exoplatform.wallet.model.WalletType;
import org.exoplatform.wallet.service.WalletAccountService;
import org.exoplatform.wallet.utils.WalletUtils;

import io.meeds.portal.permlink.model.PermanentLinkObject;
import io.meeds.portal.permlink.plugin.PermanentLinkPlugin;

public class WalletPermanentLinkPlugin implements PermanentLinkPlugin {

private static final String OBJECT_TYPE = "wallet";

public static final String URL_FORMAT = "/portal/%s/wallet";

private SpaceService spaceService;

private WalletAccountService walletAccountService;

private UserPortalConfigService portalConfigService;

public WalletPermanentLinkPlugin(SpaceService spaceService,
WalletAccountService walletAccountService,
UserPortalConfigService portalConfigService) {
this.spaceService = spaceService;
this.walletAccountService = walletAccountService;
this.portalConfigService = portalConfigService;
}

@Override
public String getObjectType() {
return OBJECT_TYPE;
}

@Override
public boolean canAccess(PermanentLinkObject object, Identity identity) throws ObjectNotFoundException {
String identityId = object.getObjectId();
Wallet wallet = walletAccountService.getWalletByIdentityId(Long.parseLong(identityId));
return wallet != null && WalletUtils.canAccessWallet(wallet, identity.getUserId());
}

@Override
public String getDirectAccessUrl(PermanentLinkObject object) throws ObjectNotFoundException {
String identityId = object.getObjectId();
Wallet wallet = walletAccountService.getWalletByIdentityId(Long.parseLong(identityId));
String url = WalletType.isSpace(wallet.getType()) ? getSpaceUrl(spaceService.getSpaceByPrettyName(wallet.getName())) :
getProfileUrl();
if (object.getParameters() != null && object.getParameters().containsKey("transactionHash")) {
url += "?hash=" + object.getParameters().get("transactionHash");
}
return url;
}

public String getSpaceUrl(Space space) {
StringBuilder spaceUrl = new StringBuilder("/portal/g/");
spaceUrl.append(space.getGroupId().replace("/", ":"))
.append("/")
.append(space.getPrettyName())
.append("/SpaceWallet");
return spaceUrl.toString();
}

public String getProfileUrl() {
return String.format(URL_FORMAT, portalConfigService.getMetaPortal());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ protected NotificationInfo makeNotification(NotificationContext ctx) {
.with(USER, requestSenderDetail.getName())
.with(USER_URL, getPermanentLink(requestSenderDetail))
.with(SENDER, requestSenderAccountDetail.getName())
.with(SENDER_ID, String.valueOf(requestSenderAccountDetail.getTechnicalId()))
.with(RECEIVER, requestReceiverAccountDetail.getName())
.with(RECEIVER_ID, String.valueOf(requestReceiverAccountDetail.getTechnicalId()))
.with(SYMBOL, symbol)
.with(MESSAGE, message)
.key(getKey())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import static org.exoplatform.wallet.utils.WalletUtils.MESSAGE_PARAMETER;
import static org.exoplatform.wallet.utils.WalletUtils.RECEIVER;
import static org.exoplatform.wallet.utils.WalletUtils.RECEIVER_ACCOUNT_DETAIL_PARAMETER;
import static org.exoplatform.wallet.utils.WalletUtils.RECEIVER_ID;
import static org.exoplatform.wallet.utils.WalletUtils.RECEIVER_TYPE;
import static org.exoplatform.wallet.utils.WalletUtils.RECEIVER_URL;
import static org.exoplatform.wallet.utils.WalletUtils.SENDER;
import static org.exoplatform.wallet.utils.WalletUtils.SENDER_ACCOUNT_DETAIL_PARAMETER;
import static org.exoplatform.wallet.utils.WalletUtils.SENDER_ID;
import static org.exoplatform.wallet.utils.WalletUtils.SENDER_URL;
import static org.exoplatform.wallet.utils.WalletUtils.SYMBOL;
import static org.exoplatform.wallet.utils.WalletUtils.SYMBOL_PARAMETER;
Expand Down Expand Up @@ -114,7 +116,9 @@ protected NotificationInfo makeNotification(NotificationContext ctx) {
.with(SENDER_URL, getPermanentLink(senderAccountDetail))
.with(RECEIVER_URL, getPermanentLink(receiverAccountDetail))
.with(SENDER, senderAccountDetail.getName())
.with(SENDER_ID, String.valueOf(senderAccountDetail.getTechnicalId()))
.with(RECEIVER, receiverAccountDetail.getName())
.with(RECEIVER_ID, String.valueOf(receiverAccountDetail.getTechnicalId()))
.key(getKey())
.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ protected NotificationInfo makeNotification(NotificationContext ctx) {
.with(SENDER_URL, getPermanentLink(senderAccountDetail))
.with(RECEIVER_URL, getPermanentLink(receiverAccountDetail))
.with(SENDER, senderAccountDetail.getName())
.with(SENDER_ID, String.valueOf(senderAccountDetail.getTechnicalId()))
.with(RECEIVER, receiverAccountDetail.getName())
.with(RECEIVER_ID, String.valueOf(receiverAccountDetail.getTechnicalId()))
.key(getKey())
.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd" xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">

<component>
<type>io.meeds.wallet.permlink.plugin.WalletPermanentLinkPlugin</type>
</component>

<component>
<key>WalletMetamaskFeatureProperties</key>
<type>org.exoplatform.container.ExtendedPropertyConfigurator</type>
Expand Down
45 changes: 44 additions & 1 deletion wallet-webapps/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,58 @@ along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<gatein-resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/gatein_resources_1_4 http://www.exoplatform.org/xml/ns/gatein_resources_1_4" xmlns="http://www.exoplatform.org/xml/ns/gatein_resources_1_4">
<gatein-resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/gatein_resources_1_5 http://www.exoplatform.org/xml/ns/gatein_resources_1_5" xmlns="http://www.exoplatform.org/xml/ns/gatein_resources_1_5">

<portal-skin>
<skin-name>Enterprise</skin-name>
<skin-module>wallet</skin-module>
<css-path>/skin/css/wallet.css</css-path>
<css-priority>110</css-priority>
<filtered>true</filtered>
</portal-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>WalletAPI</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>Wallet</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>SpaceWallet</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>WalletSettings</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>WalletOverview</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet-skin>
<application-name>wallet</application-name>
<portlet-name>RewardAdmin</portlet-name>
<skin-name>Enterprise</skin-name>
<additional-module>wallet</additional-module>
</portlet-skin>

<portlet>
<name>WalletAPI</name>
<module>
Expand Down
1 change: 1 addition & 0 deletions wallet-webapps/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.html</url-pattern>
<url-pattern>/i18n/*</url-pattern>
<url-pattern>/images/*</url-pattern>
</filter-mapping>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import './initComponents.js';
import './extensions.js';

const lang = eXo.env.portal.language;
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.notification.WalletNotification-${lang}.json`;
const url = `/wallet/i18n/locale.notification.WalletNotification?lang=${lang}`;

export function init() {
return exoi18n.loadLanguageAsync(lang, url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import './initComponents.js';

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;
const appId = 'WalletAdminApp';

Vue.use(WalletCommon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './initComponents.js';
Vue.use(WalletCommon);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

export function init() {
exoi18n.loadLanguageAsync(lang, url).then(i18n => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './initComponents.js';
Vue.use(WalletCommon);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

export function init(generatedToken) {
exoi18n.loadLanguageAsync(lang, url).then(i18n => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './initComponents.js';
Vue.use(Vuetify);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

export function initAPI() {
if (!window.walletAPIInitialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Vue.use(Vuetify);
const vuetify = new Vuetify(eXo.env.portal.vuetifyPreset);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

const appId = 'WalletOverview';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (extensionRegistry) {
Vue.use(WalletCommon);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

const appId = 'walletSettingsApp';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Vue.use(WalletCommon);
const vuetify = new Vuetify(eXo.env.portal.vuetifyPreset);

const lang = (eXo && eXo.env && eXo.env.portal && eXo.env.portal.language) || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;

const appId = 'RewardApp';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import './initComponents.js';

const lang = window.eXo?.env?.portal?.language || 'en';
const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.addon.Wallet-${lang}.json`;
const url = `/wallet/i18n/locale.addon.Wallet?lang=${lang}`;
const appId = 'WalletSetupAdmin';

Vue.use(WalletCommon);
Expand Down

0 comments on commit 236f5fe

Please sign in to comment.