system-administrationmantis

Add/assign multiple users to a Mantis project


I'll keep it short, I need to assign/add multiple users to the same project in Mantis (over 100+).

To create these accounts in bulk, I installed a plugin on the EC2 instance running Mantis (with the database installed directly on the same EC2) that allows importing a .csv list of users. That worked fine without any issues.

Now, I need to add all these users to the same project, and I was wondering if there's a way to do this in bulk.

While searching around, I only found that you can add multiple users by selecting them from the user list with CTRL, but they still need to be selected one by one.

I was thinking of creating an .sql script to run on the MySQL database to handle this directly, but I’m not even sure if that would work; plus, I’d prefer something slightly less "risky" or prone to errors.

Can anyone help? Thanks!


Solution

  • Ok, so in the end, I found this solution.

    I don’t know if it’s the best, but it was the only one that came to mind and worked on the first try without causing too many issues.

    1. I connected to the machine and created a .csv file, copying the list of usernames into a column.
    2. Then, I connected to the database and noted down the necessary details for the script:
      • The table containing the list of projects (and their respective IDs).
      • The table containing the list of users (and their respective IDs).
      • The name of the table that associates users with projects.
    3. Using awk, I generated the script with the info taken from the DB:
    awk '{print "INSERT INTO mantis-proj-userlist-table (project_id, user_id, access_level) SELECT project-id, id, 55 FROM users-table WHERE username = \x27" $1 "\x27;"}' user_list_file.csv > bulk_assign_project.sql
    

    1. Checking the generated file, it should contain the rows for each user, something like this:
    INSERT INTO user-project-association-table (project_id, user_id, access_level) 
    SELECT project-number, id, 55 FROM users-table WHERE username = 'actual-user-name';
    
    1. Then I ran the script with:
    mysql -u mantis_username -p database_name < bulk_assign_project.sql
    
    1. Finally, I connected to the DB to verify that the addition was successful using a simple SELECT filtering by the project ID.