Commit 2dc0519277417456372d6bde5c47bec895cc497e
1 parent
3d3c6674
Exists in
master
and in
4 other branches
bulk access roles update/deletion added
Showing
2 changed files
with
30 additions
and
0 deletions
Show diff stats
app/models/users_project.rb
| ... | ... | @@ -20,6 +20,23 @@ class UsersProject < ActiveRecord::Base |
| 20 | 20 | |
| 21 | 21 | delegate :name, :email, to: :user, prefix: true |
| 22 | 22 | |
| 23 | + def self.bulk_delete(project, user_ids) | |
| 24 | + UsersProject.transaction do | |
| 25 | + UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project| | |
| 26 | + users_project.delete | |
| 27 | + end | |
| 28 | + end | |
| 29 | + end | |
| 30 | + | |
| 31 | + def self.bulk_update(project, user_ids, project_access) | |
| 32 | + UsersProject.transaction do | |
| 33 | + UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project| | |
| 34 | + users_project.project_access = project_access | |
| 35 | + users_project.save | |
| 36 | + end | |
| 37 | + end | |
| 38 | + end | |
| 39 | + | |
| 23 | 40 | def self.bulk_import(project, user_ids, project_access) |
| 24 | 41 | UsersProject.transaction do |
| 25 | 42 | user_ids.each do |user_id| | ... | ... |
app/roles/team.rb
| ... | ... | @@ -36,4 +36,17 @@ module Team |
| 36 | 36 | UsersProject.bulk_import(self, users_ids, access_role) |
| 37 | 37 | self.update_repository |
| 38 | 38 | end |
| 39 | + | |
| 40 | + # Update multiple project users | |
| 41 | + # to same access role by user ids | |
| 42 | + def update_users_ids_to_role(users_ids, access_role) | |
| 43 | + UsersProject.bulk_update(self, users_ids, access_role) | |
| 44 | + self.update_repository | |
| 45 | + end | |
| 46 | + | |
| 47 | + # Delete multiple users from project by user ids | |
| 48 | + def delete_users_by_ids(users_ids) | |
| 49 | + UsersProject.bulk_delete(self, users_ids) | |
| 50 | + self.update_repository | |
| 51 | + end | |
| 39 | 52 | end | ... | ... |