Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-272: add "UserGroupIs" condition #222

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Linq;
using VirtoCommerce.CoreModule.Core.Common;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.CoreModule.Core.Conditions
{
public class UserGroupIsCondition : ConditionTree
{
public string[] Groups { get; set; }

/// <summary>
/// ((EvaluationContextBase)x).UserGroupsContains
/// </summary>
public override bool IsSatisfiedBy(IEvaluationContext context)
{
var result = false;
if (context is EvaluationContextBase evaluationContextBase && !Groups.IsNullOrEmpty())
{
result = evaluationContextBase.UserGroups != null;
if (result)
{
result = evaluationContextBase.UserGroups
.Any(x => Groups.Any(group => string.Equals(x, group, StringComparison.InvariantCultureIgnoreCase)));
}
}

return result;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,22 @@
<a class="__link" ng-click="openItemSelectWizard(element)">{{element.productName?element.productName + ' (' + element.productCode + ')' : 'select product' }}</a> items
</script>
<script type="text/ng-template" id="expression-UserGroupsContainsCondition.html">
User groups contains
User group contains
<div class="form-input">
<input required class="form-control" ng-model="element1.group" placeholder="Enter group" />
</div>
</script>
<script type="text/ng-template" id="expression-UserGroupIsCondition.html">
User group is
<div class="form-input">
<ui-select multiple ng-model="element1.groups" ng-controller="virtoCommerce.dynamicExpressions.conditionUserGroupsController">
<ui-select-match placeholder="{{'customer.blades.contact-detail.placeholders.groups' | translate}}">{{$item|json}}</ui-select-match>
<ui-select-choices repeat="x in groups | filter: $select.search">
<span ng-bind-html="x | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
</script>
<!--DYNAMIC CONTENT PUBLISHING-->
<script type="text/ng-template" id="expression-BlockContentCondition.html">
If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ angular.module('virtoCommerce.coreModule.common')
id: 'UserGroupsContainsCondition',
displayName: 'User group contains...'
});
dynamicExpressionService.registerExpression({
id: 'UserGroupIsCondition',
displayName: 'User group is...'
});

var availableExcludings = [
{
Expand Down Expand Up @@ -251,6 +255,9 @@ angular.module('virtoCommerce.coreModule.common')
.controller('virtoCommerce.dynamicExpressions.conditionGeoTimeZoneController', ['$scope', 'platformWebApp.common.timeZones', function ($scope, timeZones) {
$scope.timeZones = timeZones.query();
}])
.controller('virtoCommerce.dynamicExpressions.conditionUserGroupsController', ['$scope', 'platformWebApp.settings', function ($scope, settings) {
$scope.groups = settings.getValues({ id: 'Customer.MemberGroups' });
}])
.controller('virtoCommerce.dynamicExpressions.shippingMethodRewardController', ['$scope', function ($scope) {
function initialize(storeIds) {
//Use stores ($scope.stores) from parent controller virtoCommerce.marketingModule.promotionDetailController
Expand Down
Loading