• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / d9f86608-3df2-4f43-8850-71459996c82b

25 Mar 2024 12:07PM UTC coverage: 30.999% (-65.2%) from 96.206%
d9f86608-3df2-4f43-8850-71459996c82b

Pull #1710

circleci

carolyncole
Separating edit into wizard and non wizard controller methods
Pull Request #1710: Separating wizard new & edit and non wizard new & edit controller methods

956 of 3084 relevant lines covered (31.0%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.09
/app/controllers/groups_controller.rb
1
# frozen_string_literal: true
2
class GroupsController < ApplicationController
1✔
3
  def index; end
1✔
4

5
  def show
1✔
6
    @group = Group.find(params[:id])
×
7
    @can_edit = can_edit?
×
8
  end
9

10
  def edit
1✔
11
    @group = Group.find(params[:id])
×
12
    if can_edit?
×
13
      render "edit"
×
14
    else
15
      Rails.logger.warn("Unauthorized to edit group #{@group.id} (current user: #{current_user.id})")
×
16
      redirect_to groups_path
×
17
    end
18
  end
19

20
  # rubocop:disable Metrics/MethodLength
21
  def update
1✔
22
    @group = Group.find(params[:id])
×
23
    if can_edit?
×
24
      respond_to do |format|
×
25
        if @group.update(group_params)
×
26
          format.html { redirect_to group_url(@group), notice: "Group was successfully updated." }
×
27
          format.json { render :show, status: :ok, location: @group }
×
28
        else
29
          format.html { render :edit, status: :unprocessable_entity }
×
30
          format.json { render json: @group.errors, status: :unprocessable_entity }
×
31
        end
32
      end
33
    else
34
      Rails.logger.warn("Unauthorized to update group #{@group.id} (current user: #{current_user.id})")
×
35
      redirect_to groups_path
×
36
    end
37
  end
38
  # rubocop:enable Metrics/MethodLength
39

40
  # This is a JSON only endpoint
41
  def add_admin
1✔
42
    @group = Group.find(params[:id])
×
43
    @group.add_administrator(current_user, User.new_for_uid(params[:uid]))
×
44
    check_and_render
×
45
  end
46

47
  # This is a JSON only endpoint
48
  def add_submitter
1✔
49
    @group = Group.find(params[:id])
×
50
    user = @group.default_user(params[:uid])
×
51
    @group.add_submitter(current_user, user)
×
52
    check_and_render
×
53
  end
54

55
  # This is a JSON only endpoint
56
  def delete_user_from_group
1✔
57
    @group = Group.find(params[:id])
×
58
    @group.delete_permission(current_user, User.find_by(uid: params[:uid]))
×
59
    check_and_render
×
60
  end
61

62
  private
1✔
63

64
    def check_and_render
1✔
65
      if @group.errors.count > 0 && @group.errors.first.message == "Unauthorized"
×
66
        render status: :unauthorized, json: { message: "Unauthorized" }
×
67
      elsif @group.errors.count > 0
×
68
        render status: :bad_request, json: { message: @group.errors.first.message }
×
69
      else
70
        render status: :ok, json: { message: "OK" }
×
71
      end
72
    end
73

74
    # Only allow trusted parameters through.
75
    def group_params
1✔
76
      params.require(:group).permit([:title, :description])
×
77
    end
78

79
    def can_edit?
1✔
80
      current_user.can_admin? @group
×
81
    end
82
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc