Jump to content

Weekly update – 12 August 2022: New User Activity module version (v5)


ryan
 Share

Recommended Posts

I hope that you all are having a great week! This week I've been working on some updates to the User Activity module and have released version 5 in the ProDevTools board. This version focuses on adding several new requested features, including the following: 

  • New options to also detect when you (yourself) are editing the same page in 2+ windows and when you have modified a page in a different window. These are the “collide-self” and “modify-self” options in module config.

    Screen Shot 2022-08-12 at 3.15.26 PM.png
     
  • The module now keeps track of what fields have changed in the page editor and stores them with the activity so that they can be shown in the activity viewer or in page edit alerts.
     
  • When a page has been modified that is also open to another user it now presents them with a dialog giving the option to reload the page or keep editing.

    Screen Shot 2022-08-12 at 1.20.15 PM.png
     
  • A new “lock” option has been added that blocks a user from editing a page when it is already being edited by another. This is an alternative to just warning them with a pop-up, and it literally prevents them from being able to open the page in the page editor. This can be enabled in the module config and can also be optionally disabled for superuser.
     
  • A new configuration setting has been added that lets you configure the refresh time in the page list (previously it was not editable).
     
  • Added feature to limit the “you've been idle for awhile…” to the page editor only. When enabled, idle is still tracked for other admin processes, but idle alerts don't appear.
     
  • Improvements to ProcessUserActivity (the included activity viewer module), including: 1) visible vs. hidden states are now more obvious. 2) Changes made in page editor are now included in the activity information. 3) The ajax drop-down navigation summary has been improved to include more information.
     
  • Large portions of the module have been refactored into separate classes for better maintainability and other related improvements.

    Screen Shot 2022-08-12 at 3.14.12 PM.png

    Screen Shot 2022-08-12 at 3.27.30 PM.png

This week there have also been a few commits to the core, but mostly just small fixes and phpdoc improvements, so not enough to write about here, but there likely will be next week. Thanks for reading and have a great weekend!

 

  • Like 17
Link to comment
Share on other sites

@ryan - is there any chance of adding support for using this module on custom frontend forms? Maybe it's already supported somehow, but my initial limited experiments didn't seem to get me very far.

The idea is that you don't want staff editing a user profile in the admin at the same time the user is editing it themselves via their frontend interface.

Thanks!

Link to comment
Share on other sites

On 8/13/2022 at 7:58 PM, adrian said:

@ryan - is there any chance of adding support for using this module on custom frontend forms? Maybe it's already supported somehow, but my initial limited experiments didn't seem to get me very far.

The idea is that you don't want staff editing a user profile in the admin at the same time the user is editing it themselves via their frontend interface.

Thanks!

Extending on this... Would it be possible to get the API for this into the core? So that others can build modules that benefit from this feature? Like page builders for example?

Hope I'm not asking too much here, but just wanted to say that this could be a quite helpful feature for my upcoming page builder module... Though I'm really not sure, as I don't know the module at all and how it works, so take this with caution ? 

Maybe we could have the API in the core for others to build on top of it (like adrian with his forms and me with my page builder) and for everybody just wanting a plug and play "page-edit-notifications" there would be the pro module?

Link to comment
Share on other sites

  • 2 weeks later...

@ryan - just realized that I possibly wasn't very clear above. I understand that frontend users are tracked and they appear in the Access > User Activity list. What I am looking to do it tie their activity on a specified front-end URL (basically a custom profile editing form) to their user page in the admin, so that if admin editors go the user's page in the admin, they'll see the "current being edited by" warning.

Hope that makes more sense. Thanks!

Link to comment
Share on other sites

@adrian UserActivity doesn't use ajax on the front-end, so there's nothing to ping to continuously check and verify the activity is still current. Though you still could use it in a non-ajax context, or you could add your own ajax to do it.

The reason UserActivity doesn't use ajax on the front-end is just a matter of security... avoiding a place for nuisance garbage to be submitted. It hides its ajax endpoint behind the admin and requires a logged-in user for that endpoint to save an activity. You can use UserActivity's API to save activities on your own though, here's how:

$ua = $modules->get('UserActivity');
$activity = $page->url; // i.e. /members/profile-edit/
$ua->saveUserActivity($user, $activity); 

Then when you want to check if that activity is active, perhaps with a hook into something in ProcessUser or ProcessPageEdit, or even somewhere on your front-end...

$ua = $modules->get('UserActivity');
$u = $users->get('adrian'); // user object, name or id
$items = $ua->findUserActivity($u, [
  'equals' => '/members/profile-edit/',
  'seconds' => 60, // in last n seconds (default=60)
]); 
if(count($items)) {
  $this->warning("User may be editing their profile right now"); 
}


 

 

Link to comment
Share on other sites

Hi @ryan,

That is kinda what I tried already. From my testing, the first part of that code doesn't actually trigger the ajax updates. Of course the initial loading of the front end profile is logged by UserActivity by default anyway, so I don't need that for initial testing of the alert in the admin, but without it, it's not actually useful in the real world. Any ideas why the ajax wouldn't be working?

The second part works as a notifier, but to be useful I think it really needs to trigger the same dialog that UserActivity normally displays. Unfortunately the core PW warning banner doesn't really work for this because if there is more than one alert, the rest are collapsed and editors aren't going to expand it to see the "User may be editing their profile right now" message. How can we trigger the user activity alert instead?

Thanks!

 

Link to comment
Share on other sites

Sorry, seems like I need to make the ajax call to saveUserActivity() myself. That seems to be working and updating status as expected.

Now it's really just a matter of triggering that UserActivity popup alert instead of the PW warning. And of course have it triggered when an ajax triggered saveUserActivity() call is made from the frontend.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...