catalyst / totara-mod-ojt

https://github.com/catalyst/totara-mod-ojt/wiki
5 stars 21 forks source link

Manager signoff improvements #49

Closed agwells closed 8 months ago

agwells commented 11 months ago

This pull request contains a few improvements pertaining to the manager sign-off functionality.

  1. Manager signoff tasks: This is a task (i.e. a Totara notification) that tells a manager that one of their direct reports is waiting for them to sign off on a topic. However, these messages were not being sent out until after the topic had been signed off. This PR fixes that issue.

    These tasks were generated by a cron job that used a query to find topics that had changed to "complete" (or "required complete") status since the last cron run. But a task with "manager signoff" enabled can't enter those statuses until it is signed off, so the tasks were sent out too late.

    OJT topic completion records don't have a separate status for "awaiting manager signoff", and it would be difficult to add that status. This made it hard to write a SQL query to find topics ready to generate a task. So, I moved the task generating out of the cron job and into the function ojt_update_topic_completion() that runs when a topic's status may potentially update. However, this meant that, unlike with the cron approach, the system could accidentally generate multiple emails if, for instance, a user toggled the evaluation checkbox a few times quickly. So, I added a new column to the ojt_completion table to keep track of the last time a manager signoff task was sent, and used that to prevent another task from being sent for the same topic within 15 minutes (the previous cron run time).

    Since sending these tasks was the only thing the cron did, I also removed the cron.

  2. Added a permissions check to report.php and reportsignoff.php. Previously the code was directing users to one or the other of these by using a permissions check to decide which page to link to. But if a user typed in the address for either of them directly, they could go to whichever they wanted.
  3. Added a default content restriction to the rb_ojt_evalution_signoff_embedded embedded report, so that by default it limits the view to only the current user's direct reports. Now the view will work as intended "out of the box", without requiring an admin to configure it.
  4. Minor cleanup to avoid deprecation messages seen when running in PHP 8.
  5. Change the character limit on topics and topic items from 254 characters to 1000, and add client-side validation of the limit.
agwells commented 11 months ago

Replication instructions:

Replication is very similar to that for #47.

Background setup:

  1. Go to Administration -> Permissions -> Define Roles i. Ensure the role "Staff Manager" has the capability "mod/ojt:signoff" ii. Ensure the role "Trainer" has the capability "mod/ojt:evaluate"
  2. Go to Administration -> Users -> Manager Users i. Create a user with username: "manager" ii. Create a user with username "trainer" iii. Create a user with username "learner-direct-report"
    • Click "Add job assignment" and click "Choose manager".
    • Select user "manager" iv. Create a user with username "learner-other"
  3. Go to Administration -> Permissions -> Assign system roles i. Assign the "Staff Manager" role to the user "manager"
  4. Go to Administration -> Courses and Categories i. Create a new course called "OJT course" ii. Within the course, create an OJT activity called "OJT activity"
  5. Within the OJT course, go to "Course administration -> Users -> Enrolled users" i. Enrol user "trainer" with the role "Trainer" ii. Enrol the other three users with the role "Learner"
  6. Within the OJT activity, go to "Edit settings" i. Enable "Manager sign-off". Click "Save and display" ii. Click the "Edit topics" button that will appear in the upper-right of the activity's "General" screen iii. Click "Add topic" to make a topic. Call it "Topic 1" iv. Click the "+" icon next to Topic 1 to add an item to Topic 1. Call it "Topic Item 1a". Leave all checkboxes unticked. Click "Save changes".
  7. Log in as username "trainer" i. Go to the OJT activity ii. Click "Evaluate students" iii. Click "Evaluate" next to the row for learner-direct-report iv. Tick the box for "Topic Item 1a" to indicate that the learner has learned it.
    • The status icon at the top of the topic should turn to a green check mark
    • The manager sign-off red "x" should remain a red "x"
  8. Log in as username "manager" i. Look at the "Tasks" block on your dashboard.
    • See if there are any tasks there ii. Go to Current Learning -> OJT Course -> OJT Activity iii. Click "Evaluate students"
    • See whether you see entries for all users in the course, or just your direct report iv. Click "Evaluate" next to the row "learner-direct-report" v. Tick the manager sign-off box for "Topic Item 1a" vi. Return to the dashboard
    • See if there are any new tasks in the task block there

Behavior before this MR:

  1. There is no task in the task block before the manager signs off on the topic
  2. The manager sees all users in the course instead of just their direct report (unless an admin has gone into the report settings and enabled the direct reports content restriction manually)
  3. There is a new task in the task block after the manager signs off on the topic. This task tells the manager that the topic is awaiting their sign-off.

Behavior after this MR:

  1. There is a task in the task block immediately after the topic's status goes to "completed". So when the manager logs in, they see a task telling them about the topic that awaits completion.
  2. The manager sees only their direct report in the "Evaluate students" list
  3. No additional manager sign-off task is generated after the manager signs off on the topic.