Please note that for authentication the frontend keeps it's own database. So the used usernames/passwords are not available in core and need to be restored from the frontend's database. So to migrate a mailman3 instance you need to migrate the data stored in core _and_ the data stored in the frontend/django.
It looks like you are doing fine with the core stuff. I would recommend using django's builtin methods to do the rest.
You are looking for dumpdata/loaddata.
https://docs.djangoproject.com/en/2.1/ref/django-admin/#dumpdata
Note the warning about the permissions and content-type tables.
https://docs.djangoproject.com/en/2.1/ref/django-admin/#cmdoption-dumpdata-n...
If you haven't changed anything in these tables (You probably haven't) You can safely ignore these tables using the --exclude option during dumping.
A manual method to restore Users can be found inline in this reply.
On 9/26/18 12:20 AM, Conrad Holmberg wrote:
Hello: Just an update and review on a previous thread and some progress.
I'm trying to write a Python script to do the following:
- Dump all the members from a email list within mailman instance A. This includes the display name, email, password hash, and all the preferences. The output is a json file.
- Then we read this json file and create the user, membership to the email list, and the preferences into mailman instance B.
The problem is that we are trying to insert the members with the password hash and NOT a new plain text password.
A simple json dump example:
{ "password":"$6$rounds=656000$QhEAT7XCQ9tyUmJV$cj2xv3GKd8UXdSSasMZdqe0NjUL4T751nBEkdubog55jzIY1iZ5AQ4aRVeJIi1jnS1CKHHJn6nVnW.Hz91Xvk.",
"list_fqdn": "helpme@confused.com", "display_name": "Bob Nobody", "email": "nobody@nowhere.com", "preferences": { "receive_list_copy": false, "hide_address": false, "preferred_language": "en", "delivery_mode": "regular", "receive_own_postings": true, "acknowledge_posts": false, "delivery_status": "enabled" } }
The code for this within the mailman client API is pretty straight forward. However, the method for create_member will not work for our situation because the argument requires the password to be in plain text to be encrypted later. The rest of the tasks (subscribing, preferences) can be done with the mailman client with this single exception.
Now my question is irf someone can send a single piece of code example or where to look to accomplish this.
I see two options:
Using the mainman core. I believe the modified code would be something like this:
user_manager = getUtility(IUserManager) #with transaction(): new_user = user_manager.create_user( 'nobody@where.com', 'Bob Nobody') new_user.password = config.password_context.encrypt('abc123') #replace with hash new_user.password = '$6$rounds=656000$tS8sTX'
So the password is set with the hash instead of the encryption method.
Original code: new_user.password = config.password_context.encrypt('abc123') As mentioned in a previous thread, the password that is stored in core, isn't being used anywhere. So saving/restoring it is of no use.
The other possible method is through django. However, I'm not really sure where to being on this on as I've been looking over the django-mailman3 and this is the only example I can find in test_delete_account.py:
That is the correct password to save/restore.
the create_user method takes a plaintext password and hashes it. So you would need to do something like this:
user = User()
user.username = 'username'
user.email = 'email@example.com'
user.password = 'password-hash'
user.save()
Setting the password like this bypasses the hashing, which is what you want.
def setUp(self): self.mm_user = Mock() self.mm_user.user_id = "dummy" self.mailman_client.get_user.side_effect = lambda e: self.mm_user self.user = User.objects.create_user( 'testuser', 'test@example.com', 'testPass', first_name="firstname", last_name="lastname", )
self.client.login(username='testuser', password='testPass')
Again, it appears that the password is encrypted somewhere else before encrypted.
Any help on this is greatly appreciated.
Thanks
Conrad
Mailman-users mailing list -- mailman-users@mailman3.org To unsubscribe send an email to mailman-users-leave@mailman3.org https://lists.mailman3.org/mailman3/lists/mailman-users.mailman3.org/