Skip to content

Commit

Permalink
feat: Make Programs and rules publically accessible when Hub access i…
Browse files Browse the repository at this point in the history
…s Open - MEED-2811 - Meeds-io/MIPs#100 (#1275)

This change will introduce new business rules to allow open the access
to program details and its associated rules when the Hub access is open.
At the same time to have a better performances to request the programs,
the Space Registration startegy is duplicated in Program Table and thus
a migration procedure has been elaborated to make the change on existing
programs.
  • Loading branch information
boubaker authored Oct 27, 2023
1 parent 404082e commit 39a2e08
Show file tree
Hide file tree
Showing 46 changed files with 1,026 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@
</value-param>
</init-params>
</component-plugin>
<component-plugin>
<name>ProgramVisibilityUpgradePlugin</name>
<set-method>addUpgradePlugin</set-method>
<type>io.meeds.gamification.upgrade.ProgramVisibilityUpgradePlugin</type>
<description>An upgrade plugin to set a program visibility switch audience registration type</description>
<init-params>
<value-param>
<name>product.group.id</name>
<description>The groupId of the product</description>
<value>org.exoplatform.social</value>
</value-param>
<value-param>
<name>plugin.execution.order</name>
<description>The plugin execution order</description>
<value>5</value>
</value-param>
<value-param>
<name>plugin.upgrade.execute.once</name>
<description>Execute only once, not each version change</description>
<value>true</value>
</value-param>
</init-params>
</component-plugin>
</external-component-plugins>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
<%@ page import="io.meeds.gamification.service.ProgramService"%>
<%@ page import="org.exoplatform.container.ExoContainerContext"%>
<%@ page import="io.meeds.gamification.utils.Utils" %>
<%@ page import="org.exoplatform.services.security.ConversationState" %>

<%
boolean isAdministrator = Utils.isRewardingManager(ConversationState.getCurrent().getIdentity().getUserId());
boolean isProgramManager = isAdministrator || ExoContainerContext.getService(ProgramService.class).countOwnedPrograms(ConversationState.getCurrent().getIdentity().getUserId()) > 0;
if (Utils.canAccessAnonymousResources()) {
boolean isAdministrator = request.getRemoteUser() != null && Utils.isRewardingManager(request.getRemoteUser());
boolean isProgramManager = request.getRemoteUser() != null && (isAdministrator || ExoContainerContext.getService(ProgramService.class).countOwnedPrograms(request.getRemoteUser()) > 0);
%>

<div class="VuetifyApp singlePageApplication">
<div id="EngagementCenterActions">
<script type="text/javascript">
require(['PORTLET/gamification-portlets/EngagementCenterActions'], app => app.init(<%=isAdministrator%>, <%=isProgramManager%>));
</script>
</div>
</div>
<% } %>

11 changes: 11 additions & 0 deletions portlets/src/main/webapp/WEB-INF/jsp/programsOverview.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%@page import="io.meeds.gamification.utils.Utils"%>
<% if (Utils.canAccessAnonymousResources()) { %>
<div class="VuetifyApp">
<div id="programsOverview">
<script type="text/javascript">
require(['PORTLET/gamification-portlets/programsOverview'], app => app.init());
</script>
</div>
</div>
<% } %>

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
%>
<%@page import="io.meeds.gamification.utils.Utils"%>
<%
Object showLocked = request.getAttribute("showLocked");
if (Utils.canAccessAnonymousResources()) {
%>
<div class="VuetifyApp">
<div id="rulesOverview">
Expand All @@ -28,3 +30,4 @@
</script>
</div>
</div>
<% } %>
10 changes: 10 additions & 0 deletions portlets/src/main/webapp/WEB-INF/jsp/topChallengers.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%@page import="io.meeds.gamification.utils.Utils"%>
<% if (Utils.canAccessAnonymousResources()) { %>
<div class="VuetifyApp">
<div id="topChallengers">
<script type="text/javascript">
require(['PORTLET/gamification-portlets/topChallengers'], app => app.init());
</script>
</div>
</div>
<% } %>
14 changes: 5 additions & 9 deletions portlets/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</init-param>
<init-param>
<name>prefetch.resource.rest</name>
<value><![CDATA[/portal/rest/gamification/programs?type=ALL&sortByBudget=true|/portal/rest/gamification/leaderboard/filter?period=WEEK&capacity=10]]></value>
<value><![CDATA[/portal/rest/gamification/programs?type=ALL|/portal/rest/gamification/leaderboard/filter?period=WEEK&capacity=10]]></value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
Expand Down Expand Up @@ -258,14 +258,12 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/html/topChallengers.html</value>
<value>/WEB-INF/jsp/topChallengers.jsp</value>
</init-param>
<init-param>
<name>prefetch.resource.rest</name>
<value><![CDATA[/portal/rest/gamification/leaderboard/rank/all?loadCapacity=false&period=WEEK]]></value>
</init-param>
<expiration-cache>-1</expiration-cache>
<cache-scope>PUBLIC</cache-scope>
<supports>
<mime-type>text/html</mime-type>
</supports>
Expand All @@ -282,7 +280,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/WEB-INF/jsp/rulesOverview/index.jsp</value>
<value>/WEB-INF/jsp/rulesOverview.jsp</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
Expand All @@ -306,18 +304,16 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/html/programsOverview.html</value>
<value>/WEB-INF/jsp/programsOverview.jsp</value>
</init-param>
<init-param>
<name>preload.resource.bundles</name>
<value>locale.addon.Gamification</value>
</init-param>
<init-param>
<name>preload.resource.rest</name>
<value><![CDATA[/portal/rest/gamification/programs?returnSize=true&limit=3&type=ALL&status=ENABLED&includeDeleted=false&sortByBudget=true]]></value>
<value><![CDATA[/portal/rest/gamification/programs?returnSize=true&limit=4&status=ENABLED&sortBy=modifiedDate&sortDescending=true&lang=en&expand=countActiveRules]]></value>
</init-param>
<expiration-cache>-1</expiration-cache>
<cache-scope>PUBLIC</cache-scope>
<supports>
<mime-type>text/html</mime-type>
</supports>
Expand Down
7 changes: 0 additions & 7 deletions portlets/src/main/webapp/html/programsOverview.html

This file was deleted.

7 changes: 0 additions & 7 deletions portlets/src/main/webapp/html/topChallengers.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
justify-center
align-end>
<div v-if="leaderBoardArray[1]" class="transparent mx-1 align-center">
<exo-user-avatar
<user-avatar
:profile-id="leaderBoardArray[1].remoteId"
:name="leaderBoardArray[1].fullname"
:avatar-url="leaderBoardArray[1].avatarUrl"
:popover="leaderBoardArray[1].remoteId"
:size="40"
extra-class="me-2 ml-2 pa-0 mt-0 mb-1 rounded-circle elevation-1 d-inline-block"
avatar
popover
popover-left-position />
<v-card-text
class="top2 grey lighten-1 px-3 py-2 flex d-flex white--text justify-center font-weight-bold"
Expand All @@ -82,12 +84,14 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</v-card-text>
</div>
<div v-if="leaderBoardArray[0]" class="transparent mx-1 align-center">
<exo-user-avatar
<user-avatar
:profile-id="leaderBoardArray[0].remoteId"
:name="leaderBoardArray[0].fullname"
:avatar-url="leaderBoardArray[0].avatarUrl"
:popover="leaderBoardArray[0].remoteId"
:size="40"
extra-class="ml-2 me-2 pa-0 mt-0 mb-1 rounded-circle elevation-1 d-inline-block"
avatar
popover
popover-left-position />
<v-card-text
class="top1 yellow darken-1 px-3 py-2 flex d-flex white--text justify-center font-weight-bold"
Expand All @@ -96,12 +100,14 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</v-card-text>
</div>
<div v-if="leaderBoardArray[2]" class="transparent mx-1 align-center">
<exo-user-avatar
<user-avatar
:profile-id="leaderBoardArray[2].remoteId"
:name="leaderBoardArray[2].fullname"
:avatar-url="leaderBoardArray[2].avatarUrl"
:popover="leaderBoardArray[1].remoteId"
:size="40"
extra-class="me-2 ml-2 pa-0 mt-0 mb-1 rounded-circle elevation-1 d-inline-block"
avatar
popover
popover-left-position />
<v-card-text
class="top3 amber darken-1 px-3 pb-1 flex d-flex white--text justify-center font-weight-bold pt-2px"
Expand All @@ -126,14 +132,16 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
flat>
{{ item.rank }}
</v-card>
<exo-user-avatar
<user-avatar
:profile-id="item.remoteId"
:name="item.fullname"
:avatar-url="item.avatarUrl"
:popover="item.remoteId"
:bold-title="identityId && item.socialId === identityId"
:size="25"
:bold-title="item.socialId === identityId"
extra-class="me-0 pa-0 my-0 text-truncate-2"
popover-left-position
offset-x
popover />
offset-x />
<v-list-item-action class="ml-auto">
<span>{{ item.score }}</span>
</v-list-item-action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default {
});
},
retrievePrograms() {
return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/gamification/programs?type=ALL&sortByBudget=true`, {
return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/gamification/programs?type=ALL`, {
credentials: 'include',
}).then(resp => resp?.ok && resp.json())
.then(data => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 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.
*
*/
package io.meeds.gamification.constant;

public enum EntityVisibility {
RESTRICTED, OPEN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.meeds.gamification.constant.EntityFilterType;
import io.meeds.gamification.constant.EntityStatusType;
import io.meeds.gamification.constant.EntityType;
import io.meeds.gamification.constant.EntityVisibility;
import io.meeds.gamification.entity.ProgramEntity;
import io.meeds.gamification.model.filter.ProgramFilter;

Expand Down Expand Up @@ -119,6 +120,9 @@ private <T> void addQueryFilterParameters(ProgramFilter filter, TypedQuery<T> qu
if (CollectionUtils.isNotEmpty(filter.getSpacesIds())) {
query.setParameter("spacesIds", filter.getSpacesIds());
}
if (filter.getOwnerId() == 0 && (CollectionUtils.isNotEmpty(filter.getSpacesIds()) || !filter.isAllSpaces())) {
query.setParameter("openVisibility", EntityVisibility.OPEN);
}
EntityFilterType type = filter.getType();
if (type != null && type != EntityFilterType.ALL) {
query.setParameter("type", EntityType.valueOf(type.name()));
Expand Down Expand Up @@ -173,10 +177,10 @@ private void buildPredicates(ProgramFilter filter, List<String> suffixes, List<S
}
} else if (CollectionUtils.isNotEmpty(filter.getSpacesIds())) {
suffixes.add("Audience");
predicates.add("(d.audienceId IS NULL OR d.audienceId in (:spacesIds))");
predicates.add("(d.audienceId IS NULL OR d.visibility = :openVisibility OR d.audienceId in (:spacesIds))");
} else if (!filter.isAllSpaces()) {
suffixes.add("OpenAudience");
predicates.add("d.audienceId IS NULL");
predicates.add("(d.audienceId IS NULL OR d.visibility = :openVisibility)");
}
if (StringUtils.isNotBlank(filter.getSortBy())) {
suffixes.add("SortBy");
Expand Down
9 changes: 7 additions & 2 deletions services/src/main/java/io/meeds/gamification/dao/RuleDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.meeds.gamification.constant.EntityFilterType;
import io.meeds.gamification.constant.EntityStatusType;
import io.meeds.gamification.constant.EntityType;
import io.meeds.gamification.constant.EntityVisibility;
import io.meeds.gamification.entity.RuleEntity;
import io.meeds.gamification.model.filter.RuleFilter;

Expand Down Expand Up @@ -215,6 +216,10 @@ private <T> void addQueryFilterParameters(RuleFilter filter, TypedQuery<T> query
if (entityFilterType != null && entityFilterType != EntityFilterType.ALL) {
query.setParameter("filterType", EntityType.valueOf(filter.getType().name()));
}
if ((CollectionUtils.isNotEmpty(filter.getSpaceIds()) && !filter.isExcludeNoSpace())
|| (CollectionUtils.isEmpty(filter.getSpaceIds()) && !filter.isAllSpaces())) {
query.setParameter("openVisibility", EntityVisibility.OPEN);
}
}

private String getQueryFilterName(String sortField,
Expand Down Expand Up @@ -311,11 +316,11 @@ private void buildPredicates(RuleFilter filter, List<String> suffixes, List<Stri
predicates.add("r.domainEntity.audienceId in (:ids)");
} else {
suffixes.add("Audience");
predicates.add("(r.domainEntity.audienceId IS NULL OR r.domainEntity.audienceId in (:ids))");
predicates.add("(r.domainEntity.audienceId IS NULL OR r.domainEntity.visibility = :openVisibility OR r.domainEntity.audienceId in (:ids))");
}
} else if (!filter.isAllSpaces()) {
suffixes.add("OpenAudience");
predicates.add("r.domainEntity.audienceId IS NULL");
predicates.add("(r.domainEntity.audienceId IS NULL OR r.domainEntity.visibility = :openVisibility)");
}
if (CollectionUtils.isNotEmpty(filter.getExcludedRuleIds())) {
suffixes.add("ExcludeIds");
Expand Down
Loading

0 comments on commit 39a2e08

Please sign in to comment.