Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into pr/356
Browse files Browse the repository at this point in the history
Conflicts:
	app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs
	app/controllers/config.controller.js
	app/views/archetype.config.fieldset.dialog.html
  • Loading branch information
kgiszewski committed May 13, 2016
2 parents 5767ea9 + 8e00914 commit f541b50
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 12 deletions.
23 changes: 21 additions & 2 deletions app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Security;
using Newtonsoft.Json;
using Umbraco.Core;
using System;
Expand Down Expand Up @@ -29,6 +30,9 @@ public class ArchetypeFieldsetModel
[JsonProperty("expireDate")]
public DateTime? ExpireDate { get; set; }

[JsonProperty("allowedMemberGroups")]
public string AllowedMemberGroups { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ArchetypeFieldsetModel"/> class.
/// </summary>
Expand Down Expand Up @@ -139,11 +143,26 @@ private ArchetypePropertyModel GetProperty(string propertyAlias)
/// Is this fieldset disabled, either explicitly or by other means?
/// </summary>
/// <returns>true if this fieldset is disabled, false otherwise</returns>
internal bool IsDisabled()
internal bool IsAvailable()
{
return Disabled
// explicitly disabled or implicitly disabled through publishing?
var disabled = Disabled
|| (ReleaseDate.HasValue && ReleaseDate > DateTime.UtcNow)
|| (ExpireDate.HasValue && DateTime.UtcNow > ExpireDate);
if(disabled)
{
// yes - the fieldset is not available
return false;
}
// limitation on member group access?
if(string.IsNullOrEmpty(AllowedMemberGroups))
{
// no - the fieldset is available
return true;
}
// maybe - the fieldset is available if the current member is a member of the configured member groups
var currentUserGroups = Roles.GetRolesForUser() ?? new string[0];
return currentUserGroups.ContainsAny(AllowedMemberGroups.Split(','));
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ArchetypeModel()
/// </returns>
public IEnumerator<ArchetypeFieldsetModel> GetEnumerator()
{
return this.Fieldsets.Where(f => f.IsDisabled() == false).GetEnumerator();
return this.Fieldsets.Where(f => f.IsAvailable()).GetEnumerator();
}

//possibly obsolete?
Expand Down
5 changes: 4 additions & 1 deletion app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

Expand Down Expand Up @@ -36,6 +36,9 @@ public class ArchetypePreValue

[JsonProperty("enableCrossDragging")]
public bool EnableCrossDragging { get; set; }

[JsonProperty("enableMemberGroups")]
public bool EnableMemberGroups { get; set; }

[JsonProperty("hideFieldsetControls")]
public bool HideFieldsetControls { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public int Id

public bool IsDraft
{
get { return _fieldset.IsDisabled(); }
get { return _fieldset.IsAvailable() == false; }
}

public PublishedItemType ItemType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ArchetypePublishedContentSet(ArchetypeModel archetype)
var count = archetype.Fieldsets.Count();

_items = archetype.Fieldsets
.Where(x => x.IsDisabled() == false)
.Where(x => x.IsAvailable())
.Select(x => new ArchetypePublishedContent(x, this))
.ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/config.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
//define empty items
var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "dataTypeGuid": "0cc0eba1-9960-42c9-bf9b-60e150b429ae", "value": ""}';
var newFieldsetModel = '{"alias": "", "remove": false, "collapse": false, "labelTemplate": "", "icon": "", "label": "", "properties": [' + newPropertyModel + '], "group": null}';
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "startWithAddButton": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "maxFieldsets": null, "enableCollapsing": true, "enableCloning": false, "enableDisabling": true, "enableDeepDatatypeRequests": false, "enablePublishing": false, "enableCrossDragging": false, "fieldsets": [' + newFieldsetModel + '], "fieldsetGroups": []}');
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "startWithAddButton": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "maxFieldsets": null, "enableCollapsing": true, "enableCloning": false, "enableDisabling": true, "enableDeepDatatypeRequests": false, "enablePublishing": false, "enableMemberGroups": false, "enableCrossDragging": false, "fieldsets": [' + newFieldsetModel + '], "fieldsetGroups": []}');

//ini the model
$scope.model.value = $scope.model.value || defaultFieldsetConfigModel;
Expand Down
16 changes: 14 additions & 2 deletions app/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,14 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
return $scope.model.config.enablePublishing;
}

$scope.canUseMemberGroups = function() {
return $scope.model.config.enableMemberGroups;
}

//helper that returns if the "misc fieldset configuration" section should be visible
$scope.canConfigure = function () {
// currently the only thing in the "misc fieldset configuration" section is the publishing setup
return $scope.canPublish();
// currently the "misc fieldset configuration" section contains the publishing and the member groups setup
return $scope.canPublish() || $scope.canUseMemberGroups();
}

$scope.showDisableIcon = function (fieldset) {
Expand Down Expand Up @@ -523,6 +527,12 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
view: "datepicker",
value: fromUtc(fieldset.expireDate)
};
// create model for allowed member groups
fieldset.allowedMemberGroupsModel = {
alias: _.uniqueId("archetypeAllowedMemberGroups_"),
view: "membergrouppicker",
value: fieldset.allowedMemberGroups
};
}

//helper to get the correct fieldset from config
Expand Down Expand Up @@ -763,6 +773,8 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
// extract the publish configuration from the fieldsets (and convert local datetimes to UTC)
fieldset.releaseDate = toUtc(fieldset.releaseDateModel.value);
fieldset.expireDate = toUtc(fieldset.expireDateModel.value);
// extract the allowed member groups
fieldset.allowedMemberGroups = fieldset.allowedMemberGroupsModel.value;
});
});

Expand Down
6 changes: 5 additions & 1 deletion app/langs/da-dk.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"publishHelpText": "Konfigurér udgivelses- og udløbsdato for dette element",
"publishReleaseDate": "Udgivelsesdato",
"publishExpireDate": "Udløbsdato",
"settings": "Indstillinger"
"settings": "Indstillinger",
"enableMemberGroups": "Aktivér medlems-grupper",
"enableMemerGroupsDescription": "Tillad at fieldsets kun vises for specifikke medlems-grupper",
"allowedMemberGroups": "Tilladte medlems-grupper",
"allowedMemberGroupsHelpText": "Vælg de medlems-grupper, der skal kunne se dette element. Hvis der ikke er valgt nogen, kan alle se elementet."
}
6 changes: 5 additions & 1 deletion app/langs/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"publishHelpText": "Konfigurér udgivelses- og udløbsdato for dette element",
"publishReleaseDate": "Udgivelsesdato",
"publishExpireDate": "Udløbsdato",
"settings": "Indstillinger"
"settings": "Indstillinger",
"enableMemberGroups": "Aktivér medlems-grupper",
"enableMemerGroupsDescription": "Tillad at fieldsets kun vises for specifikke medlems-grupper",
"allowedMemberGroups": "Tilladte medlems-grupper",
"allowedMemberGroupsHelpText": "Vælg de medlems-grupper, der skal kunne se dette element. Hvis der ikke er valgt nogen, kan alle se elementet."
}
13 changes: 13 additions & 0 deletions app/less/archetype.less
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,19 @@
padding: 14px;
background-color: #f8f8f8;
overflow: hidden;

.allowedGroups {
.umb-membergrouppicker a {
i {
padding-right: 0;
font-size: inherit;
}

&:hover i {
color: #333;
}
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/views/archetype.config.fieldset.dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ <h4><archetype-localize key="fieldsetControls">Fieldset controls</archetype-loca
</div>
<div>
<label for="archetypeAdvancedOptionsCrossDragging"><input type="checkbox" id="archetypeAdvancedOptionsCrossDragging" ng-model="dialogData.model.enableCrossDragging" /><archetype-localize key="enableCrossDragging">Enable Cross-Archetype Dragging?</archetype-localize><small><archetype-localize key="enableCrossDraggingDescription">Allows fieldsets to be dragged into other Archetypes.</archetype-localize></small></label>
</div>
<div>
<label for="archetypeAdvancedOptionsMemberGroups"><input type="checkbox" id="archetypeAdvancedOptionsMemberGroups" ng-model="dialogData.model.enableMemberGroups" /><archetype-localize key="enableMemberGroups">Enable Member Group Access?</archetype-localize><small><archetype-localize key="enableMemerGroupsDescription">Allows fieldsets to be displayed for specified member groups only.</archetype-localize></small></label>
</div>

<h4><archetype-localize key="multipleFieldsets">Multiple fieldsets</archetype-localize></h4>
Expand Down
15 changes: 14 additions & 1 deletion app/views/archetype.default.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</div>
<div class="settings" ng-show="showSettings">
<!-- misc fieldset settings go here -->
<div ng-if="fieldset.releaseDateModel" ng-show="canPublish()">
<div ng-if="fieldset.releaseDateModel" ng-show="canPublish()" class="control-group">
<label ng-hide="model.config.hidePropertyLabels == '1'" class="control-label">
<span><archetype-localize key="publish">Publishing</archetype-localize></span>
<div class="archetypeFieldsetHelpText">
Expand All @@ -80,6 +80,19 @@
<archetype-submit-watcher active-submit-watcher="activeSubmitWatcher" load-callback="submitWatcherOnLoad" submit-callback="submitWatcherOnSubmit"></archetype-submit-watcher>
</div>
</div>
<div ng-if="fieldset.allowedMemberGroupsModel" ng-show="canUseMemberGroups()" class="control-group allowedGroups">
<label ng-hide="model.config.hidePropertyLabels == '1'" class="control-label">
<span><archetype-localize key="allowedMemberGroups">Allowed member groups</archetype-localize></span>
<div class="archetypeFieldsetHelpText">
<small><archetype-localize key="allowedMemberGroupsHelpText">Choose the member groups that should be allowed to see this item. Leave empty to allow all member groups.</archetype-localize></small>
</div>
</label>
<div ng-class="[(model.config.hidePropertyLabels == '1' ? 'controls-no-label' : 'controls')]">
<umb-editor model="fieldset.allowedMemberGroupsModel"></umb-editor>
</div>
<!-- we need a submit watcher here to make sure the allowed member groups are saved back to the model -->
<archetype-submit-watcher active-submit-watcher="activeSubmitWatcher" load-callback="submitWatcherOnLoad" submit-callback="submitWatcherOnSubmit"></archetype-submit-watcher>
</div>
</div>
</div>
</form>
Expand Down

0 comments on commit f541b50

Please sign in to comment.