Skip to content
Snippets Groups Projects

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

User Group interface

Admin interface

Admin section

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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: dzaporozhets

    any reason for this?

    By Administrator on 2012-12-26T16:32:05 (imported from GitLab project)

    By Administrator on 2012-12-26T16:32:05 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      it will be better to call it in_namespace cause if you will pass namespace(not group) if it will return you a projects list

      By Administrator on 2012-12-26T16:32:06 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:06 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      1. code duplication.
      2. dont use variable names like p, use project instead

      By Administrator on 2012-12-26T16:32:06 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:06 (imported from GitLab)

  • gitlab-qa-bot
  • 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: vsizov

      +1

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab)

  • Created by: vsizov

    Thanks

    By Administrator on 2012-12-26T08:44:56 (imported from GitLab project)

    By Administrator on 2012-12-26T08:44:56 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      hm it makes sense. At least validation should not be so strict like for path

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      why do we need html_safe here?

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:07 (imported from GitLab)

  • gitlab-qa-bot
  • 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)

  • gitlab-qa-bot
  • 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

      Yes, you are right. I will fix it. Thx :)

      By Administrator on 2012-12-26T16:32:09 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:09 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      we have path attribute which represent directory

      By Administrator on 2012-12-26T16:32:09 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:09 (imported from GitLab)

  • gitlab-qa-bot
  • 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)

  • gitlab-qa-bot
  • 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

      A good solution would be to extend the Team module and add a method to provide a user project access to projects in group projects?

      By Administrator on 2012-12-26T16:32:10 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:10 (imported from GitLab)

  • gitlab-qa-bot
  • 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)

  • gitlab-qa-bot
  • 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) }
  • gitlab-qa-bot
  • 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])
  • gitlab-qa-bot
  • 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: dzaporozhets

      yes :)

      By Administrator on 2012-12-26T16:32:12 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:12 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      split it in 2 lines via haml

      1. its more readable
      2. its easy not to noticie html_safe and add some bad data

      By Administrator on 2012-12-26T16:32:13 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:13 (imported from GitLab)

  • gitlab-qa-bot
  • 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: dzaporozhets

      Team module is a singular role. In our case its easier to make a method in Group model like add_users_to_projects

      By Administrator on 2012-12-26T16:32:13 (imported from GitLab project)

      By Administrator on 2012-12-26T16:32:13 (imported from GitLab)

  • Created by: dzaporozhets

    ok better now. few things left:

    1. html_safe
    2. code duplication in controller

    By Administrator on 2012-12-26T14:32:39 (imported from GitLab project)

    By Administrator on 2012-12-26T14:32:39 (imported from GitLab)

  • Created by: zzet

    few things left:

    1. html_safe

    Fixed in https://github.com/zzet/gitlabhq/commit/39e7a0eafe52ba8855baa3df1d609c27b2984852

    1. 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)

  • Created by: dzaporozhets

    ok seems ok. It requires some testing from me. After I will merge this one. Thank you a lot.

    By Administrator on 2012-12-26T17:23:13 (imported from GitLab project)

    By Administrator on 2012-12-26T17:23:13 (imported from GitLab)

  • Created by: dzaporozhets

    merged. thank you

    By Administrator on 2012-12-28T07:30:51 (imported from GitLab project)

    By Administrator on 2012-12-28T07:30:51 (imported from GitLab)

  • Please register or sign in to reply
    Loading