Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Aug 26, 2024
1 parent 488b2b8 commit db73932
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def user_not_authorized
elsif current_user.nil?
redirect_to sign_in_path
else
flash[:alert] = I18n.t('errors.no_rights')
flash[:alert] = I18n.t('errors.no_rights') # rubocop:disable Rails/ActionControllerFlashBeforeRender
if request.referer.present? && URI.parse(request.referer).host == request.host
redirect_to(request.referer)
else
Expand Down
4 changes: 2 additions & 2 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Activity < ApplicationRecord
MEDIA_DIR = File.join(DESCRIPTION_DIR, 'media').freeze

# We need to prefix, otherwise Rails can't generate the public? method
enum access: { public: 0, private: 1 }, _prefix: true
enum status: { ok: 0, not_valid: 1, removed: 2 }
enum :access, { public: 0, private: 1 }, prefix: true
enum :status, { ok: 0, not_valid: 1, removed: 2 }

belongs_to :repository
belongs_to :judge, optional: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/activity_read_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ActivityReadState < ApplicationRecord
scope :by_activity_name, ->(name) { where(activity: Activity.by_name(name)) }
scope :by_username, ->(name) { where(user: User.by_filter(name)) }
scope :by_filter, lambda { |filter, skip_user:, skip_content_page:|
filter.split.map(&:strip).select(&:present?).map do |part|
filter.split.map(&:strip).compact_blank.map do |part|
scopes = []
scopes << by_activity_name(part) unless skip_content_page
scopes << by_username(part) unless skip_user
Expand Down
2 changes: 1 addition & 1 deletion app/models/annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Annotation < ApplicationRecord
after_save :create_notification

scope :by_filter, lambda { |filter, skip_user:, skip_exercise:|
filter.split.map(&:strip).select(&:present?).map do |part|
filter.split.map(&:strip).compact_blank.map do |part|
scopes = []
scopes << by_exercise_name(part) unless skip_exercise
scopes << by_username(part) unless skip_user
Expand Down
4 changes: 2 additions & 2 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class Announcement < ApplicationRecord
has_many :announcement_views, dependent: :destroy
belongs_to :institution, optional: true
enum user_group: { everyone: 0, all_users: 1, students: 2, staff: 3, zeus: 4 }
enum style: { primary: 0, success: 1, danger: 2, warning: 3, info: 4 }
enum :user_group, { everyone: 0, all_users: 1, students: 2, staff: 3, zeus: 4 }
enum :style, { primary: 0, success: 1, danger: 2, warning: 3, info: 4 }

validates :text_nl, presence: true
validates :text_en, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/filterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module Filterable

included do
before_save :set_search
scope :by_filter, ->(filter) { filter.split.map(&:strip).select(&:present?).inject(self) { |query, part| query.where("#{table_name}.search LIKE ?", "%#{part}%") } }
scope :by_filter, ->(filter) { filter.split.map(&:strip).compact_blank.inject(self) { |query, part| query.where("#{table_name}.search LIKE ?", "%#{part}%") } }
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/gitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Gitable
included do
before_create :fix_remote

enum clone_status: { queued: 1, running: 2, complete: 3, failed: 4 }, _prefix: :clone
enum :clone_status, { queued: 1, running: 2, complete: 3, failed: 4 }, prefix: :clone
end

def full_path
Expand Down
4 changes: 2 additions & 2 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Course < ApplicationRecord

has_many :course_labels, dependent: :destroy

enum visibility: { visible_for_all: 0, visible_for_institution: 1, hidden: 2 }
enum registration: { open_for_all: 3, open_for_institutional_users: 0, open_for_institution: 1, closed: 2 }
enum :visibility, { visible_for_all: 0, visible_for_institution: 1, hidden: 2 }
enum :registration, { open_for_all: 3, open_for_institutional_users: 0, open_for_institution: 1, closed: 2 }

# TODO: Remove and use activities?
has_many :content_pages,
Expand Down
2 changes: 1 addition & 1 deletion app/models/course_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#

class CourseMembership < ApplicationRecord
enum status: { pending: 0, course_admin: 1, student: 2, unsubscribed: 3 }
enum :status, { pending: 0, course_admin: 1, student: 2, unsubscribed: 3 }

belongs_to :course
belongs_to :user
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#

class Event < ApplicationRecord
enum event_type: { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3 }
enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3 }
belongs_to :user, optional: true

validates :event_type, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Export < ApplicationRecord

belongs_to :user
has_one_attached :archive
enum status: { started: 0, finished: 1, failed: 2 }
enum :status, { started: 0, finished: 1, failed: 2 }

default_scope { order(id: :desc) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Institution < ApplicationRecord
IGNORED_DOMAINS_FOR_SIMILARITY = %w[gmail.com hotmail.com outlook.com yahoo.com live.com msn.com aol.com icloud.com telenet.be gmail.be live.be outlook.be hotmail.be].freeze
NEW_INSTITUTION_NAME = 'n/a'.freeze

enum category: { secondary: 0, higher: 1, other: 2 }
enum :category, { secondary: 0, higher: 1, other: 2 }

has_many :users, dependent: :restrict_with_error
has_many :providers, inverse_of: :institution, dependent: :restrict_with_error
Expand Down
2 changes: 1 addition & 1 deletion app/models/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Label < ApplicationRecord
has_many :activity_labels, dependent: :restrict_with_error
has_many :activities, through: :activity_labels

enum color: { red: 0, pink: 1, purple: 2, 'deep-purple': 3, indigo: 4, teal: 5, orange: 6, brown: 7, 'blue-gray': 8 }
enum :color, { red: 0, pink: 1, purple: 2, 'deep-purple': 3, indigo: 4, teal: 5, orange: 6, brown: 7, 'blue-gray': 8 }

scope :by_name, ->(name) { where('name LIKE ?', "%#{name}%") }

Expand Down
2 changes: 1 addition & 1 deletion app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# jwks_uri :string(255)
#
class Provider < ApplicationRecord
enum mode: { prefer: 0, redirect: 1, link: 2, secondary: 3 }
enum :mode, { prefer: 0, redirect: 1, link: 2, secondary: 3 }

PROVIDERS = [Provider::GSuite, Provider::Lti, Provider::Office365, Provider::Oidc, Provider::Saml, Provider::Smartschool, Provider::Surf, Provider::Elixir].freeze

Expand Down
2 changes: 1 addition & 1 deletion app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Question < Annotation
after_save :schedule_reset_in_progress, if: :saved_change_to_question_state?
after_commit :clear_transition

enum question_state: { unanswered: 0, in_progress: 1, answered: 2 }
enum :question_state, { unanswered: 0, in_progress: 1, answered: 2 }
alias_attribute :question_text, :annotation_text

# Used to authorize the transitions
Expand Down
2 changes: 1 addition & 1 deletion app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Series < ApplicationRecord
USER_STARTED_CACHE_STRING = '/series/%<id>s/user/%<user_id>s/started/%<updated_at>s'.freeze
USER_WRONG_CACHE_STRING = '/series/%<id>s/user/%<user_id>s/wrong/%<updated_at>s'.freeze

enum visibility: { open: 0, hidden: 1, closed: 2, timed: 3 }
enum :visibility, { open: 0, hidden: 1, closed: 2, timed: 3 }

before_save :regenerate_activity_tokens, if: :visibility_changed?
before_create :generate_access_token
Expand Down
4 changes: 2 additions & 2 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Submission < ApplicationRecord
CODE_FILENAME = 'code'.freeze
RESULT_FILENAME = 'result.json.gz'.freeze

enum status: { unknown: 0, correct: 1, wrong: 2, 'time limit exceeded': 3, running: 4, queued: 5, 'runtime error': 6, 'compilation error': 7, 'memory limit exceeded': 8, 'internal error': 9, 'output limit exceeded': 10 }
enum :status, { unknown: 0, correct: 1, wrong: 2, 'time limit exceeded': 3, running: 4, queued: 5, 'runtime error': 6, 'compilation error': 7, 'memory limit exceeded': 8, 'internal error': 9, 'output limit exceeded': 10 }

belongs_to :exercise, optional: false
belongs_to :user, optional: false
Expand Down Expand Up @@ -70,7 +70,7 @@ class Submission < ApplicationRecord
scope :by_status, ->(status) { where(status: status.in?(statuses) ? status : -1) }
scope :by_username, ->(name) { where(user: User.by_filter(name)) }
scope :by_filter, lambda { |filter, skip_user:, skip_exercise:|
filter.split.map(&:strip).select(&:present?).map do |part|
filter.split.map(&:strip).compact_blank.map do |part|
scopes = []
scopes << by_exercise_name(part) unless skip_exercise
scopes << by_username(part) unless skip_user
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class User < ApplicationRecord
ATTEMPTED_EXERCISES_CACHE_STRING = '/courses/%<course_id>s/user/%<id>s/attempted_exercises'.freeze
CORRECT_EXERCISES_CACHE_STRING = '/courses/%<course_id>s/user/%<id>s/correct_exercises'.freeze

enum permission: { student: 0, staff: 1, zeus: 2 }
enum theme: { system: 0, light: 1, dark: 2 }
enum :permission, { student: 0, staff: 1, zeus: 2 }
enum :theme, { system: 0, light: 1, dark: 2 }

belongs_to :institution, optional: true

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/exports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ExportsControllerTest < ActionDispatch::IntegrationTest
post series_exports_path(@series), params: { all: true, only_last_submission: true, with_info: true, format: :json }

assert_response :success
count = @students.map { |u| @series.exercises.map { |e| e.last_submission(u, @series) } }.flatten.select(&:present?).count
count = @students.map { |u| @series.exercises.map { |e| e.last_submission(u, @series) } }.flatten.compact_blank.count

assert_zip ActiveStorage::Blob.last.download, with_info: true, solution_count: count, data: @data
end
Expand Down

0 comments on commit db73932

Please sign in to comment.