Skip to content

Commit

Permalink
Fix the resolution logic of resources protection
Browse files Browse the repository at this point in the history
 - fix incorrect protection labels in add or edit material dialogs
 - fix missing "red key" to indicate protected resources/materials
 - fix missing Protection tab in edit resource/material dialog
 - fix indico#1595
  • Loading branch information
Jacques Dafflon committed Sep 24, 2014
1 parent c33c487 commit b281d87
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
17 changes: 8 additions & 9 deletions indico/MaKaC/webinterface/materialFactories.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ class MaterialFactoryRegistry:
}

@classmethod
def getById( cls, matId ):
def getById(cls, matId):
return cls._registry.get(matId, DefaultMaterialFactory.getInstance(matId))

@classmethod
def getList( cls ):
def getList(cls):
return cls._registry.values()

@classmethod
def getIdList( cls ):
def getIdList(cls):
return cls._registry.keys()

@classmethod
Expand All @@ -447,13 +447,11 @@ def getMaterialList(cls, target):
# NOTE: This method is a bit alien. It's just here because
# we couldn't find a better place

matDict = dict((title.lower(), title.title()) for title in cls.getAllowed(target))

matDict = dict((title.title(), title.lower()) for title in cls.getAllowed(target))
for material in target.getAllMaterialList():
matDict[material.getId()] = material.getTitle()

return sorted(matDict.iteritems(), key=lambda x: x[1])
matDict[material.getTitle().title()] = material.getId()

return [(x[1], x[0]) for x in sorted(matDict.iteritems())]


class CategoryMFRegistry(MaterialFactoryRegistry):
Expand All @@ -469,11 +467,12 @@ class ConfMFRegistry(MaterialFactoryRegistry):

class SessionMFRegistry(MaterialFactoryRegistry):

_registry = { MinutesFactory._id: MinutesFactory }
_registry = {MinutesFactory._id: MinutesFactory}


class ContribMFRegistry(MaterialFactoryRegistry):
pass


class SubContributionMFRegistry(MaterialFactoryRegistry):
pass
46 changes: 22 additions & 24 deletions indico/htdocs/js/indico/MaterialEditor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var CONVERSION_POLL_INTERVAL = 10000;

function updateMaterialList(oldList, newList) {
oldList.length = 0;

for (var i in newList) if (newList[i]) {
oldList.push(newList[i]);
}
Expand All @@ -34,14 +33,12 @@ type("AddEditMaterialDialog", [],{
//If we are editing a resource
if (args.resourceId) {
var isFatherProtected;
if(self.material.materialProtection == -1){
if (self.material.materialProtection == -1) {
isFatherProtected = false;
}
else if(self.material.materialProtection == 1){
} else if(self.material.materialProtection == 1) {
isFatherProtected = true;
}
//then its value is 0
else{
// then its value is 0
} else {
//check the value of the material's parent
isFatherProtected = self.material.parentProtected;
}
Expand Down Expand Up @@ -234,7 +231,6 @@ type("AddMaterialDialog", ["AddEditMaterialDialog","ExclusivePopupWithButtons"],

_parentText: function(args) {
var text = null;

if (args.subContId) {
text = $T("Inherit from parent Subcontribution");
} else if (args.contribId) {
Expand Down Expand Up @@ -284,9 +280,7 @@ type("AddMaterialDialog", ["AddEditMaterialDialog","ExclusivePopupWithButtons"],

// if the material is set to inherit from the parent, display it properly
// and set the inherited protection accordingly
var protection = Protection.resolveProtection(
entry.get('protection'),
entry.get('protectedOwner')?1:-1);
var protection = Protection.resolveProtection(entry.get('protection'), entry.get('hasProtectedOwner') ? 1 : -1);

var inheritanceText = Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}},
Protection.ParentRestrictionMessages[protection]);
Expand All @@ -300,11 +294,9 @@ type("AddMaterialDialog", ["AddEditMaterialDialog","ExclusivePopupWithButtons"],


} else {

this.creationMode = 'material';

text = Html.span({}, $T("This will be the first resource of type")," ", Html.span({style:{fontWeight: 'bold'}}, this._findTypeName(value)), ". ", $T("Please select who will be able to access this material type:"));

selector = new RadioFieldWidget([
['inherit', this._parentText(this.args)],
['private', Html.span({className: 'protPrivate'}, $T("Restricted: Can only be viewed by you and users/groups chosen by you from the list of users"))],
Expand Down Expand Up @@ -804,7 +796,6 @@ type("EditMaterialResourceBase", ["AddEditMaterialDialog", "ServiceDialogWithBut

_drawProtectionPane: function() {
var self = this;

var inheritanceText = Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}},
Protection.ParentRestrictionMessages[self.protection]);

Expand All @@ -817,11 +808,13 @@ type("EditMaterialResourceBase", ["AddEditMaterialDialog", "ServiceDialogWithBut
], 'nobulletsListWrapping');

self.protectionSelector.observe(function(value) {

// if 'private' is chosen or 'inherit' was chosen
// and the parent resource is protected
if (value == 0 && self.item.get('protectedOwner') ||
value == 1) {
// and the parent resource is protected or inherit and the event is protected or the event inherit from a
// protected category
var isProtected = value === 1 || (value == 0 && (self.material.materialProtection === 1 ||
((self.material.materialProtection === 0 || typeof self.material.materialProtection === 'undefined') &&
self.args.parentProtected)));
if (isProtected) {
self.tabWidget.enableTab(1);
// draw a little notification saying that
// the added tab can be used
Expand Down Expand Up @@ -913,7 +906,6 @@ type("EditMaterialDialog", ["EditMaterialResourceBase"], {
},

_success: function(response) {

this.list.set(this.materialId, null);
this.list.set(this.materialId, watchize(response.material));

Expand Down Expand Up @@ -1278,7 +1270,15 @@ type("ResourceListWidget", ["ListWidget"], {

if (resource.get('reviewingState') < 3 || (resource.get('reviewingState') == 3 && self.canReviewModify)) {
flag = resource.get('reviewingState') == 3;
var protection = Protection.resolveProtection(resource.get('protection'),self.matParams.materialProtection);
// Compute the protection of a resource
// Here self.matParams.parentProtected refers to the event itself, not the actual parent (for some reason)
// It is only checked if the resource or self.matParams.materialProtection, the parent (material) both
// inherit their protection.
// Because the material hierarchy only has a depth of 2, it works but it will break if a deeper hierarchy is
// implemented as there is no way to access the protection levels of grand-parents and above.
var protection = Protection.resolveProtection(resource.get('protection'),
(self.matParams.materialProtection ||
(self.matParams.parentProtected ? 1 : -1)));

protectionIcon = Html.span({}, protection==1?
Html.img({src: imageSrc('protected'),
Expand Down Expand Up @@ -1508,9 +1508,9 @@ type("MaterialListWidget", ["RemoteWidget", "ListWidget"], {
if(material.get('reviewingState') == 1 || material.get('reviewingState') == 0){
var protection =
Protection.resolveProtection(material.get('protection'),
material.get('protectedOwner')?1:-1);
material.get('hasProtectedOwner') ? 1 : -1);

var protectionIcon = Html.span({}, protection==1?
var protectionIcon = Html.span({}, protection == 1 ?
Html.img({src: imageSrc('protected'),
style: {verticalAlign: 'middle'},
alt: "protected",
Expand Down Expand Up @@ -1589,7 +1589,6 @@ type("MaterialListWidget", ["RemoteWidget", "ListWidget"], {
material.set('resources', obj);
self.set(id,
material);

self._updateMaterialList(material);

}
Expand Down Expand Up @@ -1639,7 +1638,6 @@ type("MaterialListWidget", ["RemoteWidget", "ListWidget"], {
}
var link = Widget.link(command(function(){openAddMaterialDialog(self.makeMaterialLoadFunction());}, $T("Add Material")));


return Html.div(
{},
Html.div({style:{textAlign: 'left'}}, link),
Expand Down

0 comments on commit b281d87

Please sign in to comment.