BigW Consortium Gitlab

group_links_controller.rb 1.37 KB
Newer Older
1 2 3
class Projects::GroupLinksController < Projects::ApplicationController
  layout 'project_settings'
  before_action :authorize_admin_project!
Phil Hughes committed
4
  before_action :authorize_admin_project_member!, only: [:update]
5 6 7

  def index
    @group_links = project.project_group_links.all
barthc committed
8 9

    @skip_groups = @group_links.pluck(:group_id)
10
    @skip_groups << project.namespace_id unless project.personal?
11 12 13
  end

  def create
barthc committed
14 15 16 17 18 19 20 21 22 23 24 25 26
    group = Group.find(params[:link_group_id]) if params[:link_group_id].present?

    if group
      return render_404 unless can?(current_user, :read_group, group)

      project.project_group_links.create(
        group: group,
        group_access: params[:link_group_access],
        expires_at: params[:expires_at]
      )
    else
      flash[:alert] = 'Please select a group.'
    end
27 28 29 30

    redirect_to namespace_project_group_links_path(project.namespace, project)
  end

31 32 33 34 35 36
  def update
    @group_link = @project.project_group_links.find(params[:id])

    @group_link.update_attributes(group_link_params)
  end

37 38 39
  def destroy
    project.project_group_links.find(params[:id]).destroy

Phil Hughes committed
40 41 42 43 44 45
    respond_to do |format|
      format.html do
        redirect_to namespace_project_group_links_path(project.namespace, project)
      end
      format.js { head :ok }
    end
46
  end
47 48 49 50 51 52

  protected

  def group_link_params
    params.require(:group_link).permit(:group_access, :expires_at)
  end
53
end