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

pulibrary / pdc_describe / 7031ff5b-e2d7-4285-af8b-e7b55adfc48a

pending completion
7031ff5b-e2d7-4285-af8b-e7b55adfc48a

Pull #899

circleci

mccalluc
Finish removal of explicit if-then in js
Pull Request #899: Move messages up to sidebar on the right which can be toggled

1623 of 1788 relevant lines covered (90.77%)

105.5 hits per line

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

66.67
/app/controllers/collections_controller.rb
1
# frozen_string_literal: true
2
class CollectionsController < ApplicationController
1✔
3
  def index; end
1✔
4

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

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

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

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

47
  # This is a JSON only endpoint
48
  def add_submitter
1✔
49
    @collection = Collection.find(params[:id])
4✔
50
    @collection.add_submitter(current_user, User.new_for_uid(params[:uid]))
4✔
51
    check_and_render
4✔
52
  end
53

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

61
  private
1✔
62

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

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

78
    def can_edit?
1✔
79
      current_user.can_admin? @collection
15✔
80
    end
81
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