Class: GroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/groups_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#new_session_path

Instance Method Details

#add_adminObject

This is a JSON only endpoint



42
43
44
45
46
# File 'app/controllers/groups_controller.rb', line 42

def add_admin
  @group = Group.find(params[:id])
  @group.add_administrator(current_user, User.new_for_uid(params[:uid]))
  check_and_render
end

#add_submitterObject

This is a JSON only endpoint



49
50
51
52
53
54
# File 'app/controllers/groups_controller.rb', line 49

def add_submitter
  @group = Group.find(params[:id])
  user = @group.default_user(params[:uid])
  @group.add_submitter(current_user, user)
  check_and_render
end

#delete_user_from_groupObject

This is a JSON only endpoint



57
58
59
60
61
# File 'app/controllers/groups_controller.rb', line 57

def delete_user_from_group
  @group = Group.find(params[:id])
  @group.delete_permission(current_user, User.find_by(uid: params[:uid]))
  check_and_render
end

#editObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/groups_controller.rb', line 10

def edit
  @group = Group.find(params[:id])
  if can_edit?
    render "edit"
  else
    Rails.logger.warn("Unauthorized to edit group #{@group.id} (current user: #{current_user.id})")
    redirect_to groups_path
  end
end

#indexObject



3
# File 'app/controllers/groups_controller.rb', line 3

def index; end

#showObject



5
6
7
8
# File 'app/controllers/groups_controller.rb', line 5

def show
  @group = Group.find(params[:id])
  @can_edit = can_edit?
end

#updateObject

rubocop:disable Metrics/MethodLength



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/groups_controller.rb', line 21

def update
  @group = Group.find(params[:id])
  if can_edit?
    respond_to do |format|
      if @group.update(group_params)
        format.html { redirect_to group_url(@group), notice: "Group was successfully updated." }
        format.json { render :show, status: :ok, location: @group }
      else
        # return 200 so the loadbalancer doesn't capture the error
        format.html { render :edit }
        format.json { render json: @group.errors }
      end
    end
  else
    Rails.logger.warn("Unauthorized to update group #{@group.id} (current user: #{current_user.id})")
    redirect_to groups_path
  end
end