Skip to content

Commit

Permalink
✨ Start of settings with controller and basic view (#43)
Browse files Browse the repository at this point in the history
* Adding setting tree and api controller

* fixed build warning

* Renames

* Changed version
  • Loading branch information
eduwardpost authored Jan 6, 2024
1 parent ff96e83 commit 1523e8b
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 20 deletions.
2 changes: 1 addition & 1 deletion uActivityPub.Tests/ActivityHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void GetActivityFromContentWithNonPublishedContentThrowsInvalidOperationE

_publishedContentCacheMock
.Setup(x => x.GetById(It.IsAny<int>()))
.Returns<IPublishedContent?>(null);
.Returns<IPublishedContent?>(null!);


var unitUnderTest = new ActivityHelper(_webRouterSettingsMock.Object, _umbracoContextAccessorMock.Object, _publishedUrlProvider.Object);
Expand Down
7 changes: 7 additions & 0 deletions uActivityPub/App_Plugins/uActivityPub/Lang/en-us.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="en" intName="English (US)" localName="English (US)" lcid="" culture="en-US">
<area alias="treeHeaders">
<key alias="sync">Synchronization</key>
<key alias="uactivitypub">uActivityPub</key>
</area>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div ng-controller="uActivityPubSettingsDashboardController as vm">
<umb-editor-view footer="false">
<umb-editor-header name="vm.page.title"
description="vm.page.description"
hide-description="false"
name-locked="true"
description-locked="true"
hide-alias="true"
hide-icon="true"
navigation="vm.page.navigation"
on-select-navigation-item="vm.selectNavigationItem(item)">
</umb-editor-header>
<umb-editor-container class="form-horizontal">
<umb-editor-sub-views sub-views="vm.page.navigation" model="vm"></umb-editor-sub-views>
</umb-editor-container>
</umb-editor-view>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(function () {
'use strict';

function dashboardController($controller,
$scope, $timeout, navigationService, eventsService) {

var vm = this;

var _settingsFolder = Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/uActivityPub/settings';

vm.selectNavigationItem = function (item) {
eventsService.emit('uactivitypub-dashboard.tab.change', item);
}

vm.page = {
title: 'uActivityPub',
description: '...',
navigation: [ ]
};

var uSyncSettings = Umbraco.Sys.ServerVariables.uSync;

if (!uSyncSettings.disabledDashboard) {
vm.page.navigation.push({
'name': 'uActivityPub',
'alias': 'uActivityPub',
'icon': 'icon-mastodon-fill',
'view': _settingsFolder + '/default.html',
'active': true
});
}

vm.page.navigation.push({
'name': 'Settings',
'alias': 'settings',
'icon': 'icon-settings',
'view': _settingsFolder + '/settings.html',
});


$timeout(function () {
navigationService.syncTree({ tree: "uActivityPub", path: "-1" });
});
}

angular.module('umbraco')
.controller('uActivityPubSettingsDashboardController', dashboardController);
})();
12 changes: 12 additions & 0 deletions uActivityPub/Authorization/SyncAuthorizationPolicies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace uActivityPub.Authorization;

/// <summary>
/// Security policy constants used in Umbraco by uSync
/// </summary>
public static class SyncAuthorizationPolicies
{
/// <summary>
/// name of the uSyncTreeAccess policy.
/// </summary>
public const string TreeAccessUActivityPub = nameof(TreeAccessUActivityPub);
}
16 changes: 16 additions & 0 deletions uActivityPub/Composers/UActivityPubComposer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using uActivityPub.Authorization;
using uActivityPub.Data;
using uActivityPub.Data.Migrations;
using uActivityPub.Helpers;
using uActivityPub.Notifications;
using uActivityPub.Services;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Web.BackOffice.Authorization;

namespace uActivityPub.Composers;

Expand All @@ -19,11 +24,22 @@ public void Compose(IUmbracoBuilder builder)
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, RunUActivitySettingsMigration>();
builder.AddNotificationHandler<UmbracoApplicationStartedNotification, SettingSeedHelper>();
builder.AddNotificationHandler<ContentPublishedNotification , ContentPublishPostHandler>();
builder.AddNotificationHandler<ServerVariablesParsingNotification, uActivityPubServerVariablesHandler>();
builder.Services.AddTransient<IInboxService, InboxService>();
builder.Services.AddTransient<IOutboxService, OutboxService>();
builder.Services.AddTransient<ISignatureService, SignatureService>();
builder.Services.AddTransient<ISingedRequestHandler, SingedRequestHandler>();
builder.Services.AddTransient<IActivityHelper, ActivityHelper>();
builder.Services.AddTransient<IUActivitySettingsService, UActivitySettingsService>();
builder.Services.AddAuthorization(o => CreatePolicies(o));
}

private static void CreatePolicies(AuthorizationOptions options, string backofficeAuthenticationScheme = Constants.Security.BackOfficeAuthenticationType)
{
options.AddPolicy(SyncAuthorizationPolicies.TreeAccessUActivityPub, policy =>
{
policy.AuthenticationSchemes.Add(backofficeAuthenticationScheme);
policy.Requirements.Add(new TreeRequirement("uActivityPubAlias"));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Authorization;
using uActivityPub.Authorization;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;

namespace uActivityPub.Controllers.PluginControllers;

[PluginController("uActivityPub")]
[Authorize(Policy = SyncAuthorizationPolicies.TreeAccessUActivityPub)]
public class UActivityPubDashboardApiController : UmbracoAuthorizedJsonController
{

/// <summary>
/// Stub - get API used to locate API in umbraco
/// </summary>
/// <returns></returns>
public bool GetApi() => true;
}
58 changes: 58 additions & 0 deletions uActivityPub/Expansions/SettingsTreeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Extensions;

namespace uActivityPub.Expansions;

[Tree("settings", "uActivityPubAlias", TreeTitle = "uActivityPub", TreeGroup = "sync", SortOrder = 5)]
public class SettingsTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator)
: TreeController(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory = menuItemCollectionFactory ?? throw new ArgumentNullException(nameof(menuItemCollectionFactory));

protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();
return nodes;
}

protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
var menu = _menuItemCollectionFactory.Create();

return menu;
}

protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
{
var rootResult = base.CreateRootNode(queryStrings);
if (rootResult.Result is not null)
{
return rootResult;
}

var root = rootResult.Value ?? throw new NullReferenceException(nameof(rootResult));

//set the route
root.RoutePath = $"{SectionAlias}/uactivitypub/dashboard";
// set the icon
root.Icon = "icon-mastodon-fill";
// could be set to false for a custom tree with a single node.
root.HasChildren = false;
//url for menu
root.MenuUrl = null;

return root;
}
}
26 changes: 26 additions & 0 deletions uActivityPub/Notifications/uActivityPubServerVariablesHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Routing;
using uActivityPub.Controllers.PluginControllers;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Extensions;

namespace uActivityPub.Notifications;

public class uActivityPubServerVariablesHandler : INotificationHandler<ServerVariablesParsingNotification>
{
private readonly LinkGenerator _linkGenerator;

/// <inheritdoc cref="INotificationHandler{TNotification}" />
public uActivityPubServerVariablesHandler(LinkGenerator linkGenerator)
{
_linkGenerator = linkGenerator;
}

public void Handle(ServerVariablesParsingNotification notification)
{
notification.ServerVariables.Add("uActivityPub", new Dictionary<string, object>
{
{ "uActivityPubService", _linkGenerator.GetUmbracoApiServiceBaseUrl<UActivityPubDashboardApiController>(controller => controller.GetApi()) }

Check warning on line 23 in uActivityPub/Notifications/uActivityPubServerVariablesHandler.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.

Check warning on line 23 in uActivityPub/Notifications/uActivityPubServerVariablesHandler.cs

View workflow job for this annotation

GitHub Actions / run_test

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.

Check warning on line 23 in uActivityPub/Notifications/uActivityPubServerVariablesHandler.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.

Check warning on line 23 in uActivityPub/Notifications/uActivityPubServerVariablesHandler.cs

View workflow job for this annotation

GitHub Actions / run_test

Possible null reference argument for parameter 'value' in 'void Dictionary<string, object>.Add(string key, object value)'.
});
}
}
5 changes: 5 additions & 0 deletions uActivityPub/build/uActivityPub.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<uSyncPackageFolder Include="$(MSBuildProjectDirectory)\App_Plugins\uActivityPub\" />
</ItemGroup>
</Project>
20 changes: 7 additions & 13 deletions uActivityPub/uActivityPub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

namespace uActivityPub;

// ReSharper disable once InconsistentNaming
public static class uActivityPub
{
public static string PackageName => "uActivityPub";
}

public class StaticAssetsBoot : IComposer
{
public void Compose(IUmbracoBuilder builder)
Expand Down Expand Up @@ -44,17 +38,17 @@ public void Filter(List<PackageManifest> manifests)
manifests.Add(new PackageManifest
{
PackageId = "uActivityPub",
PackageName = uActivityPub.PackageName,
PackageName = uActivityPubConstants.Package.Name,
Version = assembly.GetName().Version!.ToString(3),
AllowPackageTelemetry = true,
BundleOptions = BundleOptions.None,
// Scripts = new[]
// {
// $"{uSyncConstants.Package.PluginPath}/usync.{version}.min.js"
// },
BundleOptions = BundleOptions.Default,
Scripts =
[
$"{uActivityPubConstants.Package.PluginPath}/backoffice/uactivitypub/uactivitypub.dashboard.controller.js"
],
// Stylesheets = new[]
// {
// $"{uSyncConstants.Package.PluginPath}/usync.{version}.min.css"
// $"{uSyncConstants.Package.PluginPath}/uactivitypub.{version}.min.css"
// }
});
}
Expand Down
14 changes: 8 additions & 6 deletions uActivityPub/uActivityPub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<Product>uActivityPub</Product>
<PackageId>uActivityPub</PackageId>
<Version>1.0.9</Version>
<AssemblyVersion>1.0.9</AssemblyVersion>
<Version>1.0.10</Version>
<AssemblyVersion>1.0.10</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand All @@ -41,11 +41,13 @@
</PackageReference>
<PackageReference Include="Umbraco.Cms.Core" Version="13.0.3" />
<PackageReference Include="Umbraco.Cms.Infrastructure" Version="13.0.3" />
<PackageReference Include="Umbraco.Cms.Web.BackOffice" Version="13.0.3" />
<PackageReference Include="Umbraco.Cms.Web.Common" Version="13.0.3" />
</ItemGroup>

<!-- <ItemGroup>-->
<!-- <Content Include="App_Plugins\uActivityPub\**" ExcludeFromSingleFile="true" CopyToPublishDirectory="Always" />-->
<!-- </ItemGroup>-->

<ItemGroup>
<Content Include="App_Plugins\uActivityPub\**" ExcludeFromSingleFile="true" CopyToPublishDirectory="Always" CopyToOutputDirectory="PreserveNewest" />
<None Include="build\**" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions uActivityPub/uActivityPubConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace uActivityPub;

// ReSharper disable once InconsistentNaming
public static class uActivityPubConstants
{
public static class Package
{
/// <summary>
/// Name of the Package
/// </summary>
public const string Name = "uActivityPub";

/// <summary>
/// Virtual path to the plugin files
/// </summary>
public const string PluginPath = "/App_Plugins/uActivityPub";
}
}

0 comments on commit 1523e8b

Please sign in to comment.