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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 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✔
UNCOV
6
    @group = Group.find(params[:id])
×
UNCOV
7
    @can_edit = can_edit?
×
8
  end
9

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

20
  # rubocop:disable Metrics/MethodLength
21
  def update
1✔
UNCOV
22
    @group = Group.find(params[:id])
×
UNCOV
23
    if can_edit?
×
UNCOV
24
      respond_to do |format|
×
UNCOV
25
        if @group.update(group_params)
×
UNCOV
26
          format.html { redirect_to group_url(@group), notice: "Group was successfully updated." }
×
UNCOV
27
          format.json { render :show, status: :ok, location: @group }
×
28
        else
UNCOV
29
          format.html { render :edit, status: :unprocessable_entity }
×
UNCOV
30
          format.json { render json: @group.errors, status: :unprocessable_entity }
×
31
        end
32
      end
33
    else
UNCOV
34
      Rails.logger.warn("Unauthorized to update group #{@group.id} (current user: #{current_user.id})")
×
UNCOV
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✔
UNCOV
42
    @group = Group.find(params[:id])
×
UNCOV
43
    @group.add_administrator(current_user, User.new_for_uid(params[:uid]))
×
UNCOV
44
    check_and_render
×
45
  end
46

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

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

62
  private
1✔
63

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

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

79
    def can_edit?
1✔
UNCOV
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