The IPA.association_facet has been modified to take a read_only parameters. If the parameter is set to true, the Enroll and Delete buttons will not be shown. All facets under the memberindirect and memberofindirect facet groups are marked as read-only.

Ticket #1030

--
Endi S. Dewata
From f8aae9255e857ed4e10e358868b61773c81984e5 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Mon, 16 May 2011 14:40:09 -0500
Subject: [PATCH] Read-only association facet.

The IPA.association_facet has been modified to take a read_only parameters.
If the parameter is set to true, the Enroll and Delete buttons will not be
shown. All facets under the memberindirect and memberofindirect facet groups
are marked as read-only.

Ticket #1030
---
 install/ui/associate.js                 |   65 ++++++++++------------------
 install/ui/details.js                   |    2 +-
 install/ui/entitle.js                   |    2 +-
 install/ui/entity.js                    |   71 ++++++++++++++++++++++---------
 install/ui/hbac.js                      |    5 +-
 install/ui/search.js                    |    2 -
 install/ui/sudo.js                      |    5 +-
 install/ui/test/data/i18n_messages.json |    2 +-
 install/ui/test/data/ipa_init.json      |    2 +-
 ipalib/plugins/internal.py              |    2 +-
 10 files changed, 84 insertions(+), 74 deletions(-)

diff --git a/install/ui/associate.js b/install/ui/associate.js
index 679e007003c52a198bf2b30e11ac9a00919bc13b..9d04b0c85821a09de67a2a754b1c13bb823438bc 100644
--- a/install/ui/associate.js
+++ b/install/ui/associate.js
@@ -668,7 +668,6 @@ IPA.association_facet = function (spec) {
     that.other_entity = spec.other_entity;
     that.facet_group = spec.facet_group;
 
-    that.label = that.label ? that.label : (IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity);
     that.read_only = spec.read_only;
 
     that.associator = spec.associator || IPA.bulk_associator;
@@ -734,18 +733,15 @@ IPA.association_facet = function (spec) {
         var column;
         var i;
 
-
-
-
         var label = IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity;
         var pkey_name = IPA.metadata.objects[that.other_entity].primary_key;
 
         that.table = IPA.table_widget({
-            'id': that.entity_name+'-'+that.other_entity,
-            'name': pkey_name,
-            'label': label,
-            'entity_name': that.entity_name,
-            'other_entity': that.other_entity
+            id: that.entity_name+'-'+that.other_entity,
+            name: pkey_name,
+            label: label,
+            entity_name: that.entity_name,
+            other_entity: that.other_entity
         });
 
         if (that.columns.length) {
@@ -801,47 +797,34 @@ IPA.association_facet = function (spec) {
         that.facet_create_header(container);
 
         that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
-
-        var relationships = IPA.metadata.objects[that.entity_name].relationships;
-        var relationship = relationships[that.attribute_member];
-        if (!relationship) {
-            relationship = ['', '', ''];
-        }
-
         var other_label = IPA.metadata.objects[that.other_entity].label;
 
-        /* TODO: generic handling of different relationships */
-        var title = '';
-        if (relationship[0] == 'Member') {
-            title = IPA.messages.association.member;
-
-        } else if (relationship[0] == 'Member Of') {
-            title = IPA.messages.association.parent;
-        }
-
+        var title = that.title;
         title = title.replace('${entity}', that.entity_name);
         title = title.replace('${primary_key}', that.pkey);
         title = title.replace('${other_entity}', other_label);
 
         that.set_title(container, title);
 
-        that.remove_button = IPA.action_button({
-            label: IPA.messages.buttons.remove,
-            icon: 'ui-icon-trash',
-            click: function() {
-                that.show_remove_dialog();
-                return false;
-            }
-        }).appendTo(that.controls);
+        if (!that.read_only) {
+            that.remove_button = IPA.action_button({
+                label: IPA.messages.buttons.remove,
+                icon: 'ui-icon-trash',
+                click: function() {
+                    that.show_remove_dialog();
+                    return false;
+                }
+            }).appendTo(that.controls);
 
-        that.add_button = IPA.action_button({
-            label: IPA.messages.buttons.enroll,
-            icon: 'ui-icon-plus',
-            click: function() {
-                that.show_add_dialog();
-                return false;
-            }
-        }).appendTo(that.controls);
+            that.add_button = IPA.action_button({
+                label: IPA.messages.buttons.enroll,
+                icon: 'ui-icon-plus',
+                click: function() {
+                    that.show_add_dialog();
+                    return false;
+                }
+            }).appendTo(that.controls);
+        }
     };
 
     that.create_content = function(container) {
diff --git a/install/ui/details.js b/install/ui/details.js
index 44560b5b05ee0bd4ecf612e8337003dadc46f8d7..e8033b30609bc557b1f6a19b15b1986b354c4fa8 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -324,7 +324,7 @@ IPA.details_facet = function(spec) {
         that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
         var label = IPA.metadata.objects[that.entity_name].label;
 
-        var title = IPA.messages.details.settings;
+        var title = that.title;
         title = title.replace('${entity}', label);
         title = title.replace('${primary_key}', that.pkey);
 
diff --git a/install/ui/entitle.js b/install/ui/entitle.js
index 604bea907f298ec4492fe0ac42d0a6047bc8581b..7d56415c694d1394fa465a5ea9a61f42eda0ca38 100644
--- a/install/ui/entitle.js
+++ b/install/ui/entitle.js
@@ -38,7 +38,7 @@ IPA.entity_factories.entitle = function() {
             factory: IPA.entitle.entity,
             name: 'entitle'
         }).
-        facet({
+        search_facet({
             factory: IPA.entitle.search_facet,
             columns: [
                 {
diff --git a/install/ui/entity.js b/install/ui/entity.js
index dbee2b32dd9094fda33d322820a75e7c8cc0c122..22d3eaffcac98a934d5acb3189ffe60fdcf2abbe 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -34,6 +34,7 @@ IPA.facet = function (spec) {
     that.display_class = spec.display_class || 'entity-facet';
     that.name = spec.name;
     that.label = spec.label;
+    that.title = spec.title || that.label;
     that._entity_name = spec.entity_name;
 
     that.dialogs = [];
@@ -86,13 +87,13 @@ IPA.facet = function (spec) {
 
     that.create_header = function(container) {
 
-        that.title = $('<div/>', {
+        that.title_container = $('<div/>', {
             'class': 'facet-title'
         }).appendTo(container);
 
-        $('<h1/>').append(IPA.create_network_spinner()).appendTo(that.title);
+        $('<h1/>').append(IPA.create_network_spinner()).appendTo(that.title_container);
 
-        that.set_title(container, that.label);
+        that.set_title(container, that.title);
 
         that.controls = $('<div/>', {
             'class': 'facet-controls'
@@ -103,7 +104,7 @@ IPA.facet = function (spec) {
     };
 
     that.set_title = function(container, title) {
-        var element = $('h1', that.title);
+        var element = $('h1', that.title_container);
         element.html(title);
     };
 
@@ -533,13 +534,13 @@ IPA.entity_header = function(spec) {
 
     that.create = function(container) {
 
-        that.title = $('<div/>', {
+        that.title_container = $('<div/>', {
             'class': 'entity-title'
         }).appendTo(container);
 
         var title_text = $('<h3/>', {
             text: that.entity.metadata.label
-        }).appendTo(that.title);
+        }).appendTo(that.title_container);
 
         that.pkey = $('<span/>').appendTo(title_text);
 
@@ -611,8 +612,10 @@ IPA.entity_builder = function(){
 
         that.facet_groups([
             'member',
+            'memberindirect',
             'settings',
             'memberof',
+            'memberofindirect',
             'managedby'
         ]);
 
@@ -658,31 +661,42 @@ IPA.entity_builder = function(){
     };
 
     that.facet = function(spec) {
+
         spec.entity_name  = entity.name;
+
         facet = spec.factory(spec);
         entity.add_facet(facet);
+
         return that;
     };
 
     that.search_facet = function(spec) {
-        facet = IPA.search_facet({
-            entity_name: entity.name,
-            search_all: spec.search_all || false,
-            columns: spec.columns
-        });
+
+        spec.entity_name = entity.name;
+        spec.label = spec.label || IPA.messages.facets.search;
+
+        var factory = spec.factory || IPA.search_facet;
+        facet = factory(spec);
         entity.add_facet(facet);
+
         return that;
     };
 
     that.details_facet = function(spec) {
+
         var sections = spec.sections;
         spec.sections = null;
         spec.entity_name = entity.name;
-        facet = IPA.details_facet(spec);
+        spec.label = IPA.messages.details.settings;
+
+        var factory = spec.factory || IPA.details_facet;
+        facet = factory(spec);
         entity.add_facet(facet);
 
-        for (var i=0; i<sections.length; i++) {
-            that.section(sections[i]);
+        if (sections) {
+            for (var i=0; i<sections.length; i++) {
+                that.section(sections[i]);
+            }
         }
 
         return that;
@@ -698,7 +712,24 @@ IPA.entity_builder = function(){
 
         spec.facet_group = spec.facet_group || spec.attribute_member;
 
-        entity.add_facet(IPA.association_facet(spec));
+        if (spec.facet_group == 'memberindirect' || spec.facet_group == 'memberofindirect') {
+            spec.read_only = true;
+        }
+
+        spec.label = spec.label || (IPA.metadata.objects[spec.other_entity] ? IPA.metadata.objects[spec.other_entity].label : spec.other_entity);
+
+        if (!spec.title) {
+            if (spec.facet_group == 'member' || spec.facet_group == 'memberindirect') {
+                spec.title = IPA.messages.association.member;
+
+            } else if (spec.facet_group == 'memberof' || spec.facet_group == 'memberofindirect') {
+                spec.title = IPA.messages.association.memberof;
+            }
+        }
+
+        var factory = spec.factory || IPA.association_facet;
+        facet = factory(spec);
+        entity.add_facet(facet);
 
         return that;
     };
@@ -737,14 +768,14 @@ IPA.entity_builder = function(){
     that.section = function(spec) {
         spec.entity_name = entity.name;
 
-        if (!spec.label){
+        if (!spec.label) {
             var obj_messages = IPA.messages.objects[entity.name];
-            spec.label =  obj_messages[spec.name];
+            spec.label = obj_messages[spec.name];
         }
 
-        if (spec.factory){
-            section =  spec.factory(spec);
-        }else{
+        if (spec.factory) {
+            section = spec.factory(spec);
+        } else {
             section = IPA.details_list_section(spec);
         }
         facet.add_section(section);
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index a7e36282cd08f7f7ee4ecea15da233e93136615c..2b5e665455846df260b40587c458bc422282fc7d 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -29,9 +29,8 @@ IPA.entity_factories.hbacrule = function () {
             columns:['cn','usercategory','hostcategory','ipaenabledflag',
                      'servicecategory','sourcehostcategory']
         }).
-        facet({
-            factory: IPA.hbacrule_details_facet,
-            'name': 'details'
+        details_facet({
+            factory: IPA.hbacrule_details_facet
         }).
         adder_dialog({
             fields:[
diff --git a/install/ui/search.js b/install/ui/search.js
index 0047bdd479fdab1d90ad477f8fb4b2663a0c998b..dad11f1a9a1964e5c40d89ff00124d814b550797 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -29,8 +29,6 @@ IPA.search_facet = function(spec) {
     spec = spec || {};
 
     spec.name = spec.name || 'search';
-    spec.label = spec.label || IPA.messages.facets.search;
-
     spec.display_class = 'search-facet';
 
     var that = IPA.table_facet(spec);
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index e8489bcb2ed628ed97e3cd58f77aefd96b56db67..0f830acaa07b17957091990af0394c2cc06c018f 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -30,9 +30,8 @@ IPA.entity_factories.sudorule = function () {
         search_facet({
             columns:['cn','description','cmdcategory']
         }).
-        facet({
-            factory: IPA.sudorule_details_facet,
-            'name': 'details'
+        details_facet({
+            factory: IPA.sudorule_details_facet
         }).
         adder_dialog({
             fields:['cn']
diff --git a/install/ui/test/data/i18n_messages.json b/install/ui/test/data/i18n_messages.json
index f40cba0eda05afb8bafcbfb0815f98171a4c62f4..7a1d498e07fd53503a28eb1f73b0835b259c8c50 100644
--- a/install/ui/test/data/i18n_messages.json
+++ b/install/ui/test/data/i18n_messages.json
@@ -9,7 +9,7 @@
             "association": {
                 "add": "Add ${other_entity} into ${entity} ${primary_key}",
                 "member": "${other_entity} enrolled in ${entity} ${primary_key}",
-                "parent": "${entity} ${primary_key} is enrolled in the following ${other_entity}",
+                "memberof": "${entity} ${primary_key} is enrolled in the following ${other_entity}",
                 "remove": "Remove ${other_entity} from ${entity} ${primary_key}"
             },
             "buttons": {
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 4e4f06238707a2c1bdc5fd6fc85f1bc9aeae6237..84eecba774c73baf6320cf4cc55772118becf1f7 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -9963,7 +9963,7 @@
                     "association": {
                         "add": "Add ${other_entity} into ${entity} ${primary_key}",
                         "member": "${other_entity} enrolled in ${entity} ${primary_key}",
-                        "parent": "${entity} ${primary_key} is enrolled in the following ${other_entity}",
+                        "memberof": "${entity} ${primary_key} is enrolled in the following ${other_entity}",
                         "remove": "Remove ${other_entity} from ${entity} ${primary_key}"
                     },
                     "buttons": {
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 28bc3b212c70ed8ef0bdf1a371e479328d7e2b4a..ff62bb21ac6e97c3ec5fb2b4f2652b6168fdb399 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -378,7 +378,7 @@ class i18n_messages(Command):
         "association":{
             "add":_("Add ${other_entity} into ${entity} ${primary_key}"),
             "member":_("${other_entity} enrolled in ${entity} ${primary_key}"),
-            "parent":_("${entity} ${primary_key} is enrolled in the following ${other_entity}"),
+            "memberof":_("${entity} ${primary_key} is enrolled in the following ${other_entity}"),
             "remove":_("Remove ${other_entity} from ${entity} ${primary_key}"),
             },
         "widget":{
-- 
1.7.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to