Skip to content

Commit

Permalink
feat: Implement Permanent Link API - Meeds-io/MIPs#134
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed Jul 25, 2024
1 parent 3a341df commit 1775702
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 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

0 comments on commit 1775702

Please sign in to comment.