Author Topic: Contact Permission  (Read 5343 times)

SoopaBanana

  • Newbie
  • *
  • Posts: 2
    • View Profile
Contact Permission
« on: May 20, 2009, 04:34:42 pm »
When a user does not have administrator access and system permission to manage contacts, that user cannot add contacts to his own workspace even if read & write permission has been given for that workspace for contacts.

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: Contact Permission
« Reply #1 on: May 20, 2009, 05:18:20 pm »
Hi,

this bug will be fixed for next release.

thanks for reporting !

SoopaBanana

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Contact Permission
« Reply #2 on: May 20, 2009, 05:20:21 pm »
Thank you, looking forward to it!

evermorev

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Contact Permission
« Reply #3 on: May 22, 2009, 04:36:56 pm »
One quick question, although this will be addressed in the next fix, is there an SVN nightly download or nightly build where we could get this so its fixed or is there a way someone could kindly post a quick snippet of code that I could replace to fix this problem?

As it is right now everyone HAS to see all contacts if I want them to be able to add or edit a contact.

Thank you again for your great software and support.

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: Contact Permission
« Reply #4 on: May 22, 2009, 06:15:16 pm »
Hi,

We are not publishing night builds.
If you do not want an user to add/edit contacts, you must uncheck "can manage contacts" at user's permissions view.

This fix in this thread was made to allow users who cannot manage contact but has write permissions on a workspace, to add/edit only contacts which belongs to that workspace.

But if the user has "can manage contacts" checked he can edit every contact.

I think the best solution for you is to uncheck the 'can manage contacts' permission for the users you don't want to allow them, and if you want you can give them permissions in specific ws.

To make fix you have to edit the file 'application/models/contacts/Contact.class.php'
add the function
Code: [Select]
function canWriteByRoles(User $user){
    $roles = $this->getRoles();
    if (is_array($roles)) {
    foreach ($roles as $pc) {
    $p = $pc->getProject();
    if ($user->getProjectPermission($p, ProjectUsers::CAN_WRITE_CONTACTS)) {
    return true;
    }
    }
    }
    return false;
    }

And then overwrite the functions canAdd(), canEdit() and canDelete() with this ones:
Code: [Select]
    function canAdd(User $user, Project $project) {
return can_manage_contacts($user, true) || $this->canWriteByRoles($user);
    } // canAdd
       
    function canEdit(User $user) {
    if($this->getUserId()){
    // a contact that has a user assigned to it can be modified by anybody that can manage security (this is: users and permissions) or the user himself.
    return can_manage_contacts($user, true) || can_manage_security($user) || $this->getUserId() == $user->getId() || $this->canWriteByRoles($user);
    }
else
return can_manage_contacts($user, true) || $this->canWriteByRoles($user);
    } // canEdit
   
    function canDelete(User $user) {
return can_manage_contacts($user, true) || $this->canWriteByRoles($user);
    } // canDelete

greetings

evermorev

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Contact Permission
« Reply #5 on: May 22, 2009, 06:52:12 pm »
Sorry to confuse you, what I did want is what you stated above which is the solution for assigning permissions based on the workspace itself.

Now I applied the solution by adding the new code just above line 674     function canAdd(User $user, Project $project) {

I then proceeded to change the code correctly for the rest of the 3 code functions.

Now unfortunately when I click to add new contact it says: Error 500 OK click to remove.

Thats all it says. My question is did I need to put the addition snippet of code some where specific? I was very careful to make sure the {} were not messed up and to replace the right things correctly.

I have tried this process 3 times now from a backup file to ensure I wasnt mispasting something.

Any ideas?

evermorev

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Contact Permission
« Reply #6 on: May 22, 2009, 07:23:42 pm »
THANK YOU

That worked like a charm. Just one side not which I am sure will be ironed out in the next release that is NO big deal is when someone adds a contact it adds the contact but gives this error.

Missing lang: User cannot link objects click to remove

Thats just an FYI and I assume it is because this feature that I asked for a fix on ie the subject of this thread is simply not fully implemented and that will go away with the next release.

AGAIN thank you so much.

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: Contact Permission
« Reply #7 on: May 22, 2009, 07:34:20 pm »
I'm glad you could solve it.

i must apologize because i pasted a wrong code, sometimes "copy & paste" is fatal !

if you want i attach the whole Contact.class.php file with the fix.

Sorry again !
and thanks for posting