cancel
Showing results for 
Search instead for 
Did you mean: 

See some properties only for a group

rosh
Champ in-the-making
Champ in-the-making
Hi everyboby,
Can I see some properties only for a group?

Thanks,
Rosh

12 REPLIES 12

yogeshpj
Star Contributor
Star Contributor
Do you mean that some properties of the content should be visible to some specific group only ?

rosh
Champ in-the-making
Champ in-the-making
Hi YogeshPj,
thanks for your reply. Yes, that is the goal of my request.

rjohnson
Star Contributor
Star Contributor
The metadata (properties) are displayed via forms. Forms can be assigned to view, edit and create modes. To control what people can see you will need custom form templates that display fields based on the calling users group(s). Not difficult but unfortunately you will need one form set per document type OR a pretty complicated ftl template.

yogeshpj
Star Contributor
Star Contributor
You have to create different forms in share config file for each group.

rosh
Champ in-the-making
Champ in-the-making
I'm sorry, but I didn't understand how to assign a form at a group.

Can you show an example?

Thanks,

rjohnson
Star Contributor
Star Contributor
I'm not sure I agree with the need to create a form per group in share-config-custom because this is difficult to control and call (you need to make overrides to other bits of Alfresco), but you will need one template per document type or a very lengthy swicth statement as shown below.

Using Edit of a imaginary document type "mydoc:doc" which has only 2 properties (mydocSmiley Tonguerop1 and mydocSmiley Tonguerop2) as an example, I would do the following:-

Take a copy of the standard edit form template (share/WEB-INF/classes/alfresco/site-wescripts/org/alfresco/documentlibrary/forms)

Save it to your extensions directory and thenmodify the code at


            <div id="${formId}-fields" class="form-fields">
               <#list form.structure as item>
                  <#if item.kind == "set">
                     <@formLib.renderSet set=item />
                  <#else>
                     <@formLib.renderField field=form.fields[item.id] />
                  </#if>
               </#list>
            </div>


to read something like


            <div id="${formId}-fields" class="form-fields">
               <#list form.structure as item>
                  <#if item.kind == "set">
                     <@formLib.renderSet set=item />
                  <#else>
                     <#assign showMe = true >
                     <#switch form.fields[item.id]>
                        <#case "mydoc:prop1">
                            <#assign showMe = false>
                            <#assign members = people.getMembers("prop1_group")>
                            <#list members as m>
                               <#if m.id == person.userid>
                                   <#assign showMe = true >
                                   <#break>
                               </#if>
                            </#list>
                            <#break>
                        <#case "mydoc:prop2">
                            <#assign showMe = false>
                            <#assign members = people.getMembers("prop2_group")>
                            <#list members as m>
                               <#if m.name == person.properties.userName>
                                   <#assign showMe = true >
                                   <#break>
                               </#if>
                            </#list>
                            <#break>
                     </#switch>
                     <#if showMe == true>
                          <@formLib.renderField field=form.fields[item.id] />
                     </#if>
                  </#if>
               </#list>
            </div>


Then in share config custom tell the forms engine to use your template for this document type which you do by adding the line


            <edit-form template="../documentlibrary/forms/{your template name}"/>


in the edit form definition after the field-visibility tags.

rosh
Champ in-the-making
Champ in-the-making
I tried with this code


<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
            <#assign members = people.getMembers(people.getGroup("site_cs-documenti_SiteManager"))>
            <#list members as m>
               <#if m.id == person.userid>
                 <span class="viewmode-label">${field.label?html}:</span>
         <span class="viewmode-value">${field.value?html}</span>
                 <#break>
                </#if>
            </#list>
   </#if>
</div>


But it return an error:
2013-12-05 17:38:52,140  ERROR [freemarker.runtime] [http-80-71] Template processing error: "Expression people is undefined on line 4, column 36 in org/alfresco/components/form/controls/cs-property-visibility.ftl."

Expression people is undefined on line 4, column 36 in org/alfresco/components/form/controls/cs-property-visibility.ftl.
The problematic instruction:
———-
==> assignment: members=people.getMembers("ALFRESCO_ADMINISTRATORS") [on line 4, column 17 in org/alfresco/components/form/controls/cs-property-visibility.ftl]
in include "${field.control.template}" [on line 90, column 7 in org/alfresco/components/form/form.lib.ftl]
in user-directive renderField [on line 121, column 13 in org/alfresco/components/form/form.lib.ftl]
in user-directive formLib.renderSet [on line 23, column 16 in org/alfresco/components/form/form.get.html.ftl]
in user-directive formLib.renderFormContainer [on line 20, column 7 in org/alfresco/components/form/form.get.html.ftl]
———-

Java backtrace for programmers:
———-
freemarker.core.InvalidReferenceException: Expression people is undefined on line 4, column 36 in org/alfresco/components/form/controls/cs-property-visibility.ftl.

rjohnson
Star Contributor
Star Contributor
This is odd because based on your error message people.getGroup() obvisously works, but people.getMembers() obviously does not. According to the Alfersco documentation both should work.

All I can suggest it confirm that people.getGroup() actually works as a stand alone and that people.getMembers doesn't. If that is the case then I can only suggest you raise another question on these forums for help, because at that stage your issue exceeds ny experience.

You could also try using people.getContainerGroups(). This works in Javascripts and will return a list of groups that the logged in user belongs to. You could then modfy the code I sent to check against the returned groups.

rosh
Champ in-the-making
Champ in-the-making
Hi,
I tried to use people.getGroup(), but it returned the same error.

For the moment, I will use this code:
 <#if user.lastName == "xxx"> 


However, I will try to resolve my problem.

Thanks for your replies.