Upload users by CSV

Upload users by CSV

by Simon Rediss-Whitfield -
Number of replies: 19

I have uploaded user via csv but when they login for the first time (After they have created a new password and logging back in) they receive the message "Cannot edit this user's preferences"


I have gone through define roles and nothing is set to prohibit that could cause this, any ideas?

Average of ratings: -
In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Sorry and I am using Moodle 2.9.1+

In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Debug info: 
Error code: cannotedituserpreferences
Stack trace:
  • line 38 of /user/preferences.php: moodle_exception thrown

In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Have you uploaded users with CSV before, with no problems? Is there anything different in your CSV file from the usual fields? See Upload users

In reply to Mary Cooch

Re: Upload users by CSV

by Simon Rediss-Whitfield -

This is a new moodle install, this is the first time I have uploaded users via CSV on this install and have just started with a basic upload (username,firstname,lastname,email) which runs through fine, it is only after the user has changed the initial password and tries to log back in this error appears.


There is an option to continue which takes them to the dashboard but I would rather this error not appear at all.


I have gone through role permissions but cant see anything, all I can find in reference to this is in 

user\preferences.php


// Only administrators can access another user's preferences.

if (!$currentuser && !is_siteadmin($USER)) {

    throw new moodle_exception('cannotedituserpreferences', 'error');

}



In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Hi Mary, all sorted tweeked abit of code and changed the redirect from the login to the dashboard.

In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Ankita Senapati -

Can you please tell me what changes you made to get rid of that error?

In reply to Ankita Senapati

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Hi Ankita, its an easy fix, in the moodle direcotry>login>index.php


You need to edit the redirects for the login (I have done some major amendments so do not have a specific line for you but it was around line 308)

Mine now reads which redirects to site page instead of preferences

        // Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my.

        if ($homepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {

            if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {

                $urltogo = $CFG->wwwroot.'/my/';



In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Ankita Senapati -

Hi Simon,

Thanks for the help. Which moodle version are you using?
Because I cant find that code in index.php


In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by Chris Collman -
Picture of Documentation writers

Just curious.   Can an uploaded user modify their user profile?  

What is the  site settings>Appearance>Navigation>site homepage for a logged in user?  Wonder if it is "user preference".

I just got through uploading a user in the Sandbox.   I forced password change.  When the user logged in with the password, they were directed to change their password.  The continue went to the user's preferences page.   The navigation default was site.   When the user logged in a second time they went directly to the site front page.   

I like uploading a few "fake" students into Sandbox and my troublesome site to see if it is my site settings, upload file or a bug in the program.  

Like you I did some digging in permissions.   Saw a modify user profile for a student which was set to allow in the Sandbox.

The evil thought crossed my mind that just perhaps "someone" tweak some other bit of code which impacted something unintended.....been there and done that smile 


Chris

In reply to Chris Collman

Re: Upload users by CSV

by Ankita Senapati -

Hi Chris,

Yes the site homepage is set to User Preference and still I am getting the same error message.
Do have any other suggestion?
Please do help.

Thanks

In reply to Ankita Senapati

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Hi Chris and Ankita,


I have been trawling through my phps and for the life of me cannot remember where I made the changes, but what I did find in line 60 in user>editlib.php where the redirect takes place.


    if ($course->id != SITEID) {

        require_login($course);

    } else if (!isloggedin()) {

        if (empty($SESSION->wantsurl)) {

            $SESSION->wantsurl = $CFG->httpswwwroot.'/user/preferences.php';


But Chris from what I can tell from the force password change this takes them to preferences the first time around, (it did the same to me until I made another tweek the other day) maybe a tweek to this could fix your issue instead of making the numerous code changes I have, worth a try?

In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by jais taneja -

Hi Simon...


me to facing the same problem as Ankita is facing so can you please tell me what code I need to replace I mean I found the code which you mentioned above but I don't get what should I write their on behalf of that code as I am not much aware about php.

I shall be very thankful if you help me with this.

thanks,

jais

In reply to jais taneja

Re: Upload users by CSV

by Simon Rediss-Whitfield -

Hi Jais,


you would replace the last line (the $CFG>wwwroot'user/preferences' part) with 


 $CFG->wwwroot.'/my/';


As I said I think this would be a work around so ensure you keep your php editing app open to undo is this doesnt work.


If it doesnt let me know and on my lunch I will go through my php and compare it to my test server which has the original code on to try and find my original changes.

In reply to Simon Rediss-Whitfield

Re: Upload users by CSV

by jais taneja -

Hi... simon,


still getting the same error.

sad