happycog / VMG-Chosen-Member

VMG Chosen Member - Fieldtype for Expression Engine 2 and 3
http://vectormediagroup.com
23 stars 11 forks source link

Using Chosen Member for multiple authors #7

Closed GDmac closed 9 years ago

GDmac commented 10 years ago

here is an example how VMG chosen member can be used to select several members who may edit an entry (multi-author). e.g. this needs allowing members to edit entries authored by others, but with chosen member we can limit who sees the embedded channel form.

{exp:channel entries url_title="segment_3" }
  {if chosen_field:author_or_chosen=="yes"}
    {embed="group/safecracker" entry_id="{entry_id}"}
  {/if}
{/exp:channel:entries}

Added a method replace_author_or_chosen:

    function replace_author_or_choosen($field_data, $params, $tagdata = FALSE)
    {
        // user is author
        $current = $this->EE->session->userdata('member_id');
        if($current == $this->row('author_id')) return 'yes';
        // no other members chosen
        if ($field_data =='') return 'no';
        // is current user chosen?
        $list = explode('|', $this->replace_tag($field_data, $params, FALSE));
        $list[] = $this->row('author_id');
        return (in_array($current, $list)) ? 'yes' : 'no';
    }

nb. this is a proof of concept, i need to check that there is no way to circumvent basic security with safecracker/channel form (e.g. post data not catched for wrong entries)

mrw commented 10 years ago

Could you use regular EE tags for this? Checking chosen output against author_id and similar? Or were you running into issues/wanted an easier function for it?

GDmac commented 10 years ago
  1. I don't think there is a (native) way to do in_array checks or strpos checks. There is an undocumented feature to check if in_group(1|6|8) but we want to check against member_id's, not against member groups.
  2. Sidenote: if the custom field has no data then replace_tag is NOT called! however inside a conditional the replace_tag IS called for a custom field (go figure, IMO a bug) https://support.ellislab.com/bugs/detail/19942
mrw commented 10 years ago

Thanks! Passing this to @lukewilkins as well, for his thoughts.

GDmac commented 10 years ago

addendum: replace_tag is not called in conditional, only replace_modifier is called (see EE bug report details)