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-2183: Add public store setting PushMessages.Enable #9

Merged
merged 2 commits into from
Nov 5, 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
27 changes: 27 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ public static class Settings
{
public static class General
{
public static SettingDescriptor Enable { get; } = new()
{
Name = "PushMessages.Enable",
GroupName = "Push Messages|General",
ValueType = SettingValueType.Boolean,
DefaultValue = true,
IsPublic = true,
};

public static SettingDescriptor FirebaseCloudMessagingEnable { get; } = new()
{
Name = "PushMessages.FCM.Enable",
GroupName = "Push Messages|General",
ValueType = SettingValueType.Boolean,
DefaultValue = true,
IsPublic = true,
};

public static SettingDescriptor BatchSize { get; } = new()
{
Name = "PushMessages.BatchSize",
Expand All @@ -43,6 +61,7 @@ public static IEnumerable<SettingDescriptor> AllGeneralSettings
{
get
{
yield return Enable;
yield return BatchSize;
}
}
Expand Down Expand Up @@ -94,6 +113,14 @@ public static IEnumerable<SettingDescriptor> AllBackgroundJobsSettings
}
}

public static IEnumerable<SettingDescriptor> StoreSettings
{
get
{
yield return General.Enable;
}
}

public static IEnumerable<SettingDescriptor> AllSettings
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FirebaseAdmin;
Expand All @@ -10,6 +11,7 @@
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.Platform.Core.Settings;
using VirtoCommerce.Platform.Hangfire;
using VirtoCommerce.PushMessages.Core;
using VirtoCommerce.PushMessages.Core.Events;
using VirtoCommerce.PushMessages.Core.Models;
using VirtoCommerce.PushMessages.Data.BackgroundJobs;
Expand Down Expand Up @@ -62,13 +64,17 @@ public static void UseFirebaseCloudMessaging(this IApplicationBuilder appBuilder
settingsRegistrar.RegisterSettingsForType(receiverSettings, "Store");
}

private static SettingDescriptor[] ToSettings(this FcmReceiverOptions options)
private static IList<SettingDescriptor> ToSettings(this FcmReceiverOptions options)
{
return options
var settings = options
.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Select(x => CreateSetting(x.Name, x.GetValue(options)))
.ToArray();
.ToList();

settings.Insert(0, ModuleConstants.Settings.General.FirebaseCloudMessagingEnable);

return settings;
}

private static SettingDescriptor CreateSetting(string name, object value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"PushMessages:delete": "Delete PushMessages related data"
},
"settings": {
"PushMessages.Enable": {
"title": "Enable push notifications",
"description": "Enable or disable push notifications"
},
"PushMessages.FCM.Enable": {
"title": "Enable firebase cloud messaging (FCM)",
"description": "Enable or disable Firebase Cloud Messaging (FCM). Additional configuration is required use following link for configuration https://docs.virtocommerce.org/platform/user-guide/push-messages/firebase-cloud-messaging/"
},
"PushMessages.BatchSize": {
"title": "Batch size",
"description": ""
Expand Down
4 changes: 4 additions & 0 deletions src/VirtoCommerce.PushMessages.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using VirtoCommerce.PushMessages.ExperienceApi.Authorization;
using VirtoCommerce.PushMessages.ExperienceApi.Extensions;
using VirtoCommerce.PushMessages.ExperienceApi.Handlers;
using VirtoCommerce.StoreModule.Core.Model;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Infrastructure;

Expand Down Expand Up @@ -99,6 +100,9 @@ public void PostInitialize(IApplicationBuilder appBuilder)
var settingsRegistrar = serviceProvider.GetRequiredService<ISettingsRegistrar>();
settingsRegistrar.RegisterSettings(ModuleConstants.Settings.AllSettings, ModuleInfo.Id);

// Register store settings
settingsRegistrar.RegisterSettingsForType(ModuleConstants.Settings.StoreSettings, nameof(Store));

// Register permissions
var permissionsRegistrar = serviceProvider.GetRequiredService<IPermissionsRegistrar>();
permissionsRegistrar.RegisterPermissions(ModuleInfo.Id, "Push Messages", ModuleConstants.Security.Permissions.AllPermissions);
Expand Down
Loading