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

pulibrary / pdc_describe / 9cd1579d-9684-4b66-ae83-9619a7d64644

pending completion
9cd1579d-9684-4b66-ae83-9619a7d64644

Pull #1094

circleci

GitHub
Merge branch 'main' into sidekiq-prod
Pull Request #1094: Adding redis and sidekiq

1628 of 2126 relevant lines covered (76.58%)

97.58 hits per line

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

80.0
/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])
3✔
7
    @can_edit = can_edit?
3✔
8
  end
9

10
  def edit
1✔
11
    @collection = Collection.find(params[:id])
4✔
12
    if can_edit?
4✔
13
      render "edit"
3✔
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])
1✔
23
    if can_edit?
1✔
24
      respond_to do |format|
1✔
25
        if @collection.update(collection_params)
1✔
26
          format.html { redirect_to collection_url(@collection), notice: "Collection was successfully updated." }
2✔
27
          format.json { render :show, status: :ok, location: @collection }
1✔
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])
1✔
43
    @collection.add_administrator(current_user, User.new_for_uid(params[:uid]))
1✔
44
    check_and_render
1✔
45
  end
46

47
  # This is a JSON only endpoint
48
  def add_submitter
1✔
49
    @collection = Collection.find(params[:id])
1✔
50
    @collection.add_submitter(current_user, User.new_for_uid(params[:uid]))
1✔
51
    check_and_render
1✔
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"
2✔
65
        render status: :unauthorized, json: { message: "Unauthorized" }
×
66
      elsif @collection.errors.count > 0
2✔
67
        render status: :bad_request, json: { message: @collection.errors.first.message }
×
68
      else
69
        render status: :ok, json: { message: "OK" }
2✔
70
      end
71
    end
72

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

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