Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dawoe committed Jan 28, 2021
2 parents 1d071a8 + de134d6 commit d8ac92c
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 61 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/main.yml

This file was deleted.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2017

# Version format
version: 2.1.0.{build}
version: 2.2.0.{build}

branches:
only:
Expand Down
17 changes: 17 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configuration #

## Prevent deleting (v2.2.0+) ##

To prevent that editors can delete a content or media item that is linked to from other items you can add the following key to your appSettings in the web.config

<add key="nexu:PreventDelete" value="true" />

Removing this setting or setting it to false allows editors to delete the used item

## Prevent unpublishing (v2.2.0+) ##

To prevent that editors can unpublish a content item that is linked to from other items you can add the following key to your appSettings in the web.config

<add key="nexu:PreventUnpublish" value="true" />

Removing this setting or setting it to false allows editors to unpublish the used item
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

1. [Introduction](introduction.md "Introduction")
2. [Installation](installation.md)
3. [Extending](extending.md "Extending")
3. [Configuration](configuration.md)
4. [Extending](extending.md "Extending")
18 changes: 18 additions & 0 deletions src/Our.Umbraco.Nexu.Common/Constants/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Our.Umbraco.Nexu.Common.Constants
{
/// <summary>
/// The app settings constants
/// </summary>
internal class AppSettings
{
/// <summary>
/// Prevent delete app setting
/// </summary>
public const string PreventDelete = "nexu:PreventDelete";

/// <summary>
/// Prevent unpublish app setting
/// </summary>
public const string PreventUnpublish = "nexu:PreventUnpublish";
}
}
52 changes: 51 additions & 1 deletion src/Our.Umbraco.Nexu.Common/NexuContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Our.Umbraco.Nexu.Common
using System.Configuration;
using Umbraco.Core;

namespace Our.Umbraco.Nexu.Common
{
/// <summary>
/// Represents the nexu context.
Expand All @@ -23,6 +26,8 @@ private NexuContext()
this.isProcessing = false;
this.itemInProgress = string.Empty;
this.itemsProcessed = 0;
this.PreventDelete = this.GetAppSetting<bool>(Constants.AppSettings.PreventDelete, false);
this.PreventUnPublish = this.GetAppSetting<bool>(Constants.AppSettings.PreventUnpublish, false);
instance = this;
}

Expand Down Expand Up @@ -84,5 +89,50 @@ public int ItemsProcessed
}
}
}

/// <summary>
/// Gets a value indicating whether prevent delete.
/// </summary>
public bool PreventDelete { get; }

/// <summary>
/// Gets a value indicating whether prevent un publish.
/// </summary>
public bool PreventUnPublish { get; set; }


/// <summary>
/// Gets the value of app setting
/// </summary>
/// <param name="key">
/// The key.
/// </param>
/// <param name="defaultValue">The default value when the app setting is empty or not found.</param>
/// <typeparam name="T">
/// The return type
/// </typeparam>
/// <returns>
/// The <see cref="T"/>.
/// </returns>
private T GetAppSetting<T>(string key, T defaultValue)
{
var value = defaultValue;

var setting = ConfigurationManager.AppSettings[key];

if (setting == null)
{
return value;
}

var attempConvert = setting.TryConvertTo<T>();

if (attempConvert.Success)
{
value = attempConvert.Result;
}

return value;
}
}
}
1 change: 1 addition & 0 deletions src/Our.Umbraco.Nexu.Common/Our.Umbraco.Nexu.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Constants\AppSettings.cs" />
<Compile Include="Constants\DatabaseConstants.cs" />
<Compile Include="Constants\RelationTypes.cs" />
<Compile Include="Interfaces\Repositories\IRelationRepository.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
angular.extend(this, $controller('Umbraco.Editors.Content.DeleteController', { $scope: $scope }));
}


$scope.links = {};
$scope.preventDelete = false;
$scope.links = {};
$scope.descendantsHaveLinks = false;
$scope.isLoading = true;
$scope.showlanguage = true;
Expand All @@ -19,6 +19,12 @@
$scope.links = result.relations;
$scope.descendantsHaveLinks = result.descendantsUsed;

if (Umbraco.Sys.ServerVariables.Nexu.PreventDelete) {
if ($scope.links.length > 0 || $scope.descendantsHaveLinks) {
$scope.preventDelete = true;
}
}

$scope.isLoading = false;

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

// inherit base delete controller
angular.extend(this, $controller('Our.Umbraco.Nexu.BaseDeleteController', { $scope: $scope }));

}]);
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@

function init() {
service.checkRelations(editorState.current.udi).then(function (data) {
$scope.model.disableSubmitButton = false;
vm.relations = data.relations;
vm.descendantsHaveLinks = data.descendantsUsed;
$scope.model.disableSubmitButton = false;

if (Umbraco.Sys.ServerVariables.Nexu.PreventUnPublish) {
if (vm.relations.length > 0 || vm.descendantsHaveLinks) {
$scope.model.disableSubmitButton = true;
}
}

vm.loading = false;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
<nexu-relation-list relations="links" show-language="showlanguage" items-per-page="itemsPerPage" />
</div>

<p class="abstract">
<p class="abstract" ng-if="!preventDelete">
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize> <strong>{{currentNode.name}}</strong>?
</p>

<div ng-if="descendantsHaveLinks" class="umb-alert">
<localize key="nexu_descendantsWarning"></localize>
</div>

<div class="umb-alert umb-alert--warning">
<div class="umb-alert umb-alert--warning" ng-if="!preventDelete">
<localize key="defaultdialogs_variantdeletewarning">This will delete the node and all its languages. If you only want to delete one language go and unpublish it instead.</localize>
</div>

<umb-confirm on-confirm="performDelete" confirm-button-style="danger" on-cancel="cancel"></umb-confirm>

<umb-confirm ng-if="!preventDelete" on-confirm="performDelete" confirm-button-style="danger" on-cancel="cancel"></umb-confirm>

<umb-confirm ng-if="preventDelete" confirm-button-style="danger" on-cancel="cancel"></umb-confirm>


</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
<nexu-relation-list relations="links" show-language="showlanguage" items-per-page="itemsPerPage" />
</div>

<p class="umb-abstract">
<p class="umb-abstract" ng-if="!preventDelete">
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize> <strong>{{currentNode.name}}</strong> ?
</p>

<div ng-if="descendantsHaveLinks" class="umb-alert">
<localize key="nexu_descendantsWarning"></localize>
</div>

<umb-confirm on-confirm="performDelete" on-cancel="close">
</umb-confirm>
<umb-confirm ng-if="!preventDelete" on-confirm="performDelete" confirm-button-style="danger" on-cancel="close"></umb-confirm>

<umb-confirm ng-if="preventDelete" confirm-button-style="danger" on-cancel="close"></umb-confirm>


</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Our.Umbraco.Nexu.Web.Composing.Components
using Our.Umbraco.Nexu.Common;

namespace Our.Umbraco.Nexu.Web.Composing.Components
{
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -51,6 +53,8 @@ private void ServerVariablesParserParsing(object sender, Dictionary<string, obje

urlDictionairy.Add("RebuildApi", urlHelper.GetUmbracoApiServiceBaseUrl<RebuildApiController>(c => c.GetRebuildStatus()));
urlDictionairy.Add("RelationCheckApi", urlHelper.GetUmbracoApiServiceBaseUrl<RelationCheckApiController>(c => c.GetIncomingLinks(null)));
urlDictionairy.Add("PreventDelete", NexuContext.Current.PreventDelete);
urlDictionairy.Add("PreventUnPublish", NexuContext.Current.PreventUnPublish);

if (!e.Keys.Contains("Nexu"))
{
Expand Down

0 comments on commit d8ac92c

Please sign in to comment.