Feature/add user to projects in group (issue #2298)
Created by: zzet
Added the ability to add a user to multiple projects, grouped projects via Group page (admin section and User section). Existing rights in the projects are the same (as borrowed logic teams Role)
This PR for issue #2298 (closed) (Add users to group)
Some screenshots
User interface
Admin interface
Merge request reports
Activity
64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, 80 82 scope :public_only, where(private_flag: false) 81 83 scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } 82 84 scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } 85 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } 53 53 54 54 if @project 55 55 @team_member = @project.users_projects.new 56 else 57 @team_member = UsersProject.new 56 58 end 57 59 end 58 60 61 def team_members 62 @group.add_users_to_project_teams(params[:user_ids], params[:project_access]) 53 53 54 54 if @project 55 55 @team_member = @project.users_projects.new 56 else 57 @team_member = UsersProject.new 56 58 end 57 59 end 58 60 61 def team_members 62 @group.add_users_to_project_teams(params[:user_ids], params[:project_access]) 64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, 66 = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" 67 68 = form_tag project_teams_update_admin_group_path(@group), id: "new_team_member", class: "bulk_import", method: :put do 69 %table.zebra-striped 70 %thead 71 %tr 72 %th Users 73 %th Project Access: 74 75 - @group.users.each do |u| 76 %tr{class: "user_#{u.id}"} 77 %td.name= link_to u.name, admin_user_path(u) 78 %td.projects_access 79 - u.projects.in_namespace(@group).each do |project| 80 - u_p = u.users_projects.in_project(project).first 81 %span 64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, Created by: zzet
I would like to discuss with you the need to validate the names of the repository (the project), but decided to do so after giving the code. In fact - we use the name of the project in the future for the name of the directory that will host the repository itself on the disk. In this case, this test is not very different from the way. It is difficult to say how high should be the degree of freedom of project names, but the choice of white path with an extended range of valid characters is not a bad thing. As a starting point, I think, quite a test. If necessary, it can be expanded.
I usually prefer not to trust users :)
By Administrator on 2012-12-26T16:32:08 (imported from GitLab project)
By Administrator on 2012-12-26T16:32:08 (imported from GitLab)
80 82 scope :public_only, where(private_flag: false) 81 83 scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } 82 84 scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } 85 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } 64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, 66 = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" 67 68 = form_tag project_teams_update_admin_group_path(@group), id: "new_team_member", class: "bulk_import", method: :put do 69 %table.zebra-striped 70 %thead 71 %tr 72 %th Users 73 %th Project Access: 74 75 - @group.users.each do |u| 76 %tr{class: "user_#{u.id}"} 77 %td.name= link_to u.name, admin_user_path(u) 78 %td.projects_access 79 - u.projects.in_namespace(@group).each do |project| 80 - u_p = u.users_projects.in_project(project).first 81 %span Created by: zzet
This line I used a short string concatenation is the project name and a link to edit the user rights in the project. Result is the text and html tag links that do not select a secure html will render with a tag. There is an option to not use html_safe and break this conclusion on two lines with the work of HAML, or leave in a single line. if you remember the fact that the title of the project is validated by us and nothing dangerous in it does not slip - we can safely use html_safe.
By Administrator on 2012-12-26T16:32:09 (imported from GitLab project)
By Administrator on 2012-12-26T16:32:09 (imported from GitLab)
53 53 54 54 if @project 55 55 @team_member = @project.users_projects.new 56 else 57 @team_member = UsersProject.new 56 58 end 57 59 end 58 60 61 def team_members 62 @group.add_users_to_project_teams(params[:user_ids], params[:project_access]) 64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, Created by: zzet
Yes, of course I remember it. But the rejection of validation - not a good solution, although this critical None. The only question is, what degree of freedom must be in the title. Nothing more :)
By Administrator on 2012-12-26T16:32:10 (imported from GitLab project)
By Administrator on 2012-12-26T16:32:10 (imported from GitLab)
80 82 scope :public_only, where(private_flag: false) 81 83 scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } 82 84 scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } 85 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } Created by: zzet
Fixed https://github.com/zzet/gitlabhq/commit/8ec9be82c9166516a73d2e9974b002b411ced6f4
By Administrator on 2012-12-26T16:32:11 (imported from GitLab project)
By Administrator on 2012-12-26T16:32:11 (imported from GitLab)
53 53 54 54 if @project 55 55 @team_member = @project.users_projects.new 56 else 57 @team_member = UsersProject.new 56 58 end 57 59 end 58 60 61 def team_members 62 @group.add_users_to_project_teams(params[:user_ids], params[:project_access]) Created by: zzet
dont use variable names like p, use project instead
fixed https://github.com/zzet/gitlabhq/commit/3313627d7424abc72ab0a9117d7c94d73ad50609
By Administrator on 2012-12-26T16:32:11 (imported from GitLab project)
By Administrator on 2012-12-26T16:32:11 (imported from GitLab)
64 64 # Validations 65 65 validates :owner, presence: true 66 66 validates :description, length: { within: 0..2000 } 67 validates :name, presence: true, length: { within: 0..255 } 67 validates :name, presence: true, length: { within: 0..255 }, 68 format: { with: Gitlab::Regex.project_name_regex, 66 = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" 67 68 = form_tag project_teams_update_admin_group_path(@group), id: "new_team_member", class: "bulk_import", method: :put do 69 %table.zebra-striped 70 %thead 71 %tr 72 %th Users 73 %th Project Access: 74 75 - @group.users.each do |u| 76 %tr{class: "user_#{u.id}"} 77 %td.name= link_to u.name, admin_user_path(u) 78 %td.projects_access 79 - u.projects.in_namespace(@group).each do |project| 80 - u_p = u.users_projects.in_project(project).first 81 %span 53 53 54 54 if @project 55 55 @team_member = @project.users_projects.new 56 else 57 @team_member = UsersProject.new 56 58 end 57 59 end 58 60 61 def team_members 62 @group.add_users_to_project_teams(params[:user_ids], params[:project_access]) Created by: zzet
few things left:
- html_safe
Fixed in https://github.com/zzet/gitlabhq/commit/39e7a0eafe52ba8855baa3df1d609c27b2984852
- code duplication in controller
Fixed in https://github.com/zzet/gitlabhq/commit/98044f0f143552943b8afad0c8133f236a857adb
By Administrator on 2012-12-26T16:49:57 (imported from GitLab project)
By Administrator on 2012-12-26T16:49:57 (imported from GitLab)
Created by: zzet
From what we discussed today was just a matter of a regular expression https://github.com/gitlabhq/gitlabhq/pull/2389/files#L14R10
By Administrator on 2012-12-26T16:56:14 (imported from GitLab project)
By Administrator on 2012-12-26T16:56:14 (imported from GitLab)