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

uclibs / aaec / 1b60dccf-78d1-4f34-b64c-1f1b8c28e44d

12 Mar 2024 10:10PM UTC coverage: 82.5% (-17.4%) from 99.874%
1b60dccf-78d1-4f34-b64c-1f1b8c28e44d

Pull #400

circleci

Janell-Huyck
Add parallelism to .circleci/config.yml
Pull Request #400: 399 - Add parallelism to .circleci/config.yml

660 of 800 relevant lines covered (82.5%)

11.49 hits per line

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

44.9
/app/controllers/admin_controller.rb
1
# frozen_string_literal: true
2

3
class AdminController < ApplicationController
1✔
4
  include AdminOnlyAccess
1✔
5

6
  skip_before_action :require_authenticated_user, only: %i[login validate]
1✔
7
  skip_before_action :check_date
1✔
8
  skip_before_action :check_admin, only: %i[login validate]
1✔
9

10
  ALLOWED_CONTROLLERS_TO_MODELS = {
11
    'artworks' => Artwork,
1✔
12
    'books' => Book,
13
    'book_chapters' => BookChapter,
14
    'digital_projects' => DigitalProject,
15
    'editings' => Editing,
16
    'films' => Film,
17
    'journal_articles' => JournalArticle,
18
    'musical_scores' => MusicalScore,
19
    'photographies' => Photography,
20
    'physical_media' => PhysicalMedium,
21
    'plays' => Play,
22
    'public_performances' => PublicPerformance,
23
    'submitters' => Submitter,
24
    'other_publications' => OtherPublication
25
  }.freeze
26

27
  def login; end
1✔
28

29
  def validate
1✔
30
    if check_credentials(params[:username], params[:password])
7✔
31
      reset_session
7✔
32
      session[:admin] = true
7✔
33
      redirect_to publications_path
7✔
34
    else
35
      flash.keep[:danger] = 'Invalid Credentails'
×
36
      redirect_to manage_path
×
37
    end
38
  end
39

40
  # Generates a CSV file for a given model. This method is restricted
41
  # to admin users through the AdminOnlyAccess concern.
42
  def csv
1✔
43
    if params[:id].nil? && allowed_model
×
44
      begin
45
        @instance_variable = allowed_model.all
×
46
        respond_to do |format|
×
47
          format.html { redirect_to publications_path }
×
48
          format.csv { send_data @instance_variable.to_csv }
×
49
        end
50
      rescue StandardError => e
51
        logger.error "CSV generation failed: #{e}"
×
52
        flash.keep[:danger] = 'Something went wrong while generating the CSV.'
×
53
        redirect_to publications_path
×
54
      end
55
    else
56
      redirect_to publications_path
×
57
    end
58
  end
59

60
  # Generates a citations report. This method is restricted to admin
61
  # users through the AdminOnlyAccess concern.
62
  def citations
1✔
63
    all_publications = fetch_all_records
×
64
    @college_array = []
×
65

66
    College.find_each do |college|
×
67
      publications_in_college = all_publications.select do |publication|
×
68
        publication.respond_to?(:college_ids) && publication.college_ids.include?(college.id)
×
69
      end
70

71
      grouped_by_department = publications_in_college.group_by(&:uc_department)
×
72

73
      sorted_departments = grouped_by_department.transform_values do |publications|
×
74
        publications.sort_by do |publication|
×
75
          full_names = publication.author_last_name.zip(publication.author_first_name).map { |last, first| "#{last.downcase}, #{first.downcase}" }
×
76
          [full_names, publication.work_title.downcase]
×
77
        end
78
      end.sort.to_h
79

80
      @college_array << [college.id, sorted_departments]
×
81
    end
82
  end
83

84
  def toggle_links
1✔
85
    session[:links] = session[:links] == false
4✔
86
    redirect_to citations_path
4✔
87
  end
88

89
  private
1✔
90

91
  def check_credentials(username, password)
1✔
92
    username == ENV['ADMIN_USERNAME'] && password == ENV['ADMIN_PASSWORD']
7✔
93
  end
94

95
  def allowed_model
1✔
96
    ALLOWED_CONTROLLERS_TO_MODELS[params[:controller_name]]
×
97
  end
98

99
  def fetch_all_records
1✔
100
    all_records = []
×
101
    ALLOWED_CONTROLLERS_TO_MODELS.each_value do |model|
×
102
      all_records += model.all
×
103
    end
104
    all_records
×
105
  end
106
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

© 2026 Coveralls, Inc