Custom Field that only the admin group can edit

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Field that only the admin group can edit

jfotto2
I have the following requirement to edit Bugzilla.
Create a custom field and that anyone can initially populate when creating the bug, but only allow the members of the admin group edit the field once the bug has been submitted.

I have created about 5 custom fields, but need to restrict the editing of 2 of these fields to only people in the admin group.  
If a user is not in the admin group, I only want to display the value (editable=false)

Any help would be appreciated
Thanks
_______________________________________________
support-bugzilla mailing list
[hidden email]
https://lists.mozilla.org/listinfo/support-bugzilla
PLEASE put [hidden email] in the To: field when you reply.
Reply | Threaded
Open this post in threaded view
|

Re: Custom Field that only the admin group can edit

jfotto2
On Monday, July 31, 2017 at 11:44:19 AM UTC-4, Thorsten Schöning wrote:

> Guten Tag [hidden email],
> am Montag, 31. Juli 2017 um 17:39 schrieben Sie:
>
> > I have created about 5 custom fields, but need to restrict the
> > editing of 2 of these fields to only people in the admin group.  
> > If a user is not in the admin group, I only want to display the value (editable=false)
>
> You need to create an extension to check for field changes and
> customize templates to show the difference to the user.
>
> https://bugzilla.readthedocs.io/en/5.0/integrating/extensions.html#altering-who-can-change-what
> https://bugzilla.readthedocs.io/en/5.0/integrating/index.html
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning       E-Mail: [hidden email]
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
>
> Telefon...........05151-  9468- 55
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow

I have been able to use the "user.in_group()" function to control the editing of the default fields, but am having trouble finding the information in the edit.html.tmpl file to perform the same control on the custom fields.   I am not much of a perl programmer, and have only scratch the surface of the template tool.
Can you provide me any more information or examples on how to do what I am trying to do?
Thanks...
Jim
_______________________________________________
support-bugzilla mailing list
[hidden email]
https://lists.mozilla.org/listinfo/support-bugzilla
PLEASE put [hidden email] in the To: field when you reply.
Reply | Threaded
Open this post in threaded view
|

Re: Custom Field that only the admin group can edit

jfotto2
On Monday, July 31, 2017 at 12:23:57 PM UTC-4, Thorsten Schöning wrote:

> Guten Tag [hidden email],
> am Montag, 31. Juli 2017 um 17:58 schrieben Sie:
>
> > I have been able to use the "user.in_group()" function to control
> > the editing of the default fields, but am having trouble finding the
> > information in the edit.html.tmpl file to perform the same control
> > on the custom fields.
>
> Having a quick look, the templates seem to already take permissions
> checks on custom fields into account. "bug.check_can_change_field"
> results in the documented hook being called, so in theory you should
> only need to write your hook and deal with your field names.
>
> > [%############################################################################%]
> > [%# Block for Custom Fields                                                  #%]
> > [%############################################################################%]
>
> > [% BLOCK section_customfields %]
> > [%# *** Custom Fields *** %]
> >   [% USE Bugzilla %]
> >   [% FOREACH field = Bugzilla.active_custom_fields %]
> >     <tr>
> >       [%# Use PROCESS instead of INCLUDE, because extra_field_item is defined
> >         # in the template and must be returned back. INCLUDE cannot do that. %]
> >       [% PROCESS bug/field.html.tmpl value = bug.${field.name}
> >                                      editable = bug.check_can_change_field(field.name, 0, 1) %]
> >     </tr>
> >     [% IF extra_field_item %]
> >       <tr>
> >         <th class="field_label">[% extra_field_item.header FILTER none %]</th>
> >         <td>[% extra_field_item.data FILTER none %]</td>
> >       </tr>
> >     [% END %]
> >   [% END %]
> > [% END %]
>
> Bugzilla::Bug:
>
> > sub check_can_change_field {
> > [...]
> >         my @priv_results;
> >     Bugzilla::Hook::process('bug_check_can_change_field',
> >         { bug => $self, field => $field,
> >           new_value => $newvalue, old_value => $oldvalue,
> >           priv_results => \@priv_results });
> >     if (my $priv_required = first { $_ > 0 } @priv_results) {
> >         $$PrivilegesRequired = $priv_required;
> >         return 0;
> >     }
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning       E-Mail: [hidden email]
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
>
> Telefon...........05151-  9468- 55
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow

Here was my solution to this problem.  I hope other people can benefit from my discovery

   [% FOREACH field = Bugzilla.active_custom_fields %]
     <tr>
       [%# Use PROCESS instead of INCLUDE, because extra_field_item is defined
         # in the template and must be returned back. INCLUDE cannot do that. %]
       [% IF field.name == 'cf_{custom_field_name}' %]
           [% IF user.in_group("admin") %]  
               [% PROCESS bug/field.html.tmpl value = bug.${field.name} editable = 1 %]
           [% ELSE %]
               [% PROCESS bug/field.html.tmpl value = bug.${field.name} editable = 0 %]
           [% END %]
       [% ELSE %]
           [% PROCESS bug/field.html.tmpl value = bug.${field.name} editable = 1 %]
       [% END %]
     </tr>
_______________________________________________
support-bugzilla mailing list
[hidden email]
https://lists.mozilla.org/listinfo/support-bugzilla
PLEASE put [hidden email] in the To: field when you reply.