How to modify what consitutes a Lead's "Owner"

  1. We have a logic hook that automatically assigns new Website leads to an appropriate agent, based on a number of variables.
  2. We have a role, “agent” which restricts leads viewed to “owner.”
  3. When a lead is assigned, the agent gets notified via e-mail and SMS that they have a new lead. They then have an hour in which they must click a link and follow instructions to either accept or decline the lead. If they fail it is reassigned to another agent.

Agents are not employees of the company, but independent contractors who split commissions from company-provided leads.
THEREFOR, we want them to accept a lead before having access to it.
Unfortunately, they can currently log into SuiteCRM, and see all leads assigned to them (whether accepted yet or not).

What I need to do (in an upgrade-safe way, of course) is require the following conditions to be true before showing a lead to a user:
leads.assigned_user_id="$current_user->id" AND leads_cstm.assignment_status_c=“accepted”

Any ideas?

Thanks!

I found I can accomplish this client-side by adding the following jQuery to /custom/modules/Leads/tpls/DetailViewHeader.tpl:

{literal}
<script>
 $(document).ready(function(){
  var assignment_status_c = '{/literal}{$bean->assignment_status_c}{literal}';
  var agent = '{/literal}{$bean->assigned_user_id}{literal}';
  var lead = '{/literal}{$bean->id}{literal}';
  {/literal}
  {if is_admin($current_user)}var isAdmin='1';{else}var isAdmin='0';{/if}
  {literal}
  if(assignment_status_c !== 'accepted' && isAdmin !== '1'){
   $('div#content').html('<h1 style="color:#f00;text-align:center;position:relative;top:135px;margin-bottom:200px;">You must <a href="https://www.DOMAIN.com/accept_reject_lead.htm?agent='+agent+'&lead='+lead+'&accept=1">accept</a> this lead before you can view contact details.</h1>');
  }
 });
</script>
{/literal}

But when I tried the same with EditViewHeader.tpl, I ran into conflicts, so I just created a file “custom/modules/Leads/views/view.edit.php” with the following:

if($this->bean->assignment_status_c != 'accepted' && $GLOBALS['current_user']->id == $this->bean->assigned_user_id){
 die('You must accept a lead before you can edit it.');
}else{
 include('modules/Leads/views/view.edit.php');
}

Nothing fancy, but it does what we need.
Anyone have a more elegant solution?

Thanks!