Best practice forum (Archived)

Automatically assigning manager

 
Darren Roberts
Automatically assigning manager
by Darren Roberts - Wednesday, 11 June 2014, 2:40 AM
 

Hi

Using Totara 2.6 is there any way of automatically assigning a specific user as the manager for all other users?

The reasoning behind this is we're not using the position heirarchy, but we require all program/certification overdue notifications for all users to be emailed to a single dedicated email address. So I figured the easiest way to do this would be to setup a user whos email address is the dedicated mailbox, and then assign them as every users manager.

As users get added to the system though they would need to have this setup manually, as single or bulk upload (not Totara Sync) doesn't allow you to set the manager there and then.

I figured to get round that we could have a nightly executed stored procedure in the database that adds a row to the pos_assignment table for any users who aren't setup in there already. However the reportstoid column has me confused and seems to link in with a number of other tables through a more complex relationship, which possibly makes direct manipulation of this table a bad idea unless I could just always use the same "reportstoid" value for all records?

Otherwise any ideas how I could achieve this? How easy would it be to amend the programs to just directly send to the mailbox, or hardcode the mailbox users id instead of selecting the users manager and where would I find that code?

Thanks, Darren

Darren Roberts
Re: Automatically assigning manager
by Darren Roberts - Wednesday, 11 June 2014, 3:25 AM
 

Possibly answering my own question... are there any negative consequences to changing the query in the function totara_get_manager() in totara/core/totara.php to just return the mailbox user instead of looking for a record in pos_assignment?

So it would become a simple:

SELECT * FROM {user} WHERE id = 18

(18 being the mailbox users id)

From what I can tell that seems to be the primary way for the messages getting the manager in order to send the notification.

Ciaran Irvine (Core Developer)
Re: Automatically assigning manager
by Ciaran Irvine (Core Developer) - Wednesday, 11 June 2014, 4:25 PM
 

Well, you could do that, but you would have to remember to update that code after every upgrade. And there's no guarantee it wouldn't have obscure unintended side effects in some scenarios.

Your original idea of a nightly job to fix all the new users was probably better. reportstoid is actually a link to the role_assignments table - when a user is assigned as a manager then you need to assign them as having the staffmanager role in the user context. So for the fields in role_assignments

roleid: the id of the staffmanager role

contextid: from mdl_context, id where contextlevel=30 and instanceid= user id of the subordinate

userid: the manager id (18)

In your case managerpath in pos_assignment is easy, it'll always be /18/x where x is the user id of the subordinate

As long as the pos_assignment and role_assignment records are set up properly most functionality should work OK.

Simon Coggins
Re: Automatically assigning manager
by Simon Coggins - Wednesday, 11 June 2014, 5:04 PM
Group Totara

Rather than trying to hack the table at a low level, you would be better off using the assign_user_position() function. That will handle all the low level stuff like paths and role assignments. You could look at the usage in /user/position.php and write a script that makes use of it.

Simon

 

Darren Roberts
Re: Automatically assigning manager
by Darren Roberts - Tuesday, 17 June 2014, 6:59 AM
 

Thanks both. In the event I've gone with your suggestion Simon - I'd forgotten just how easy it is to write a basic bespoke plugin with a cron called function! (don't get to do it very often...)

All looking good now. Thanks again!