Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:44 +02:00
parent fe4000916c
commit 6cbecb5b39
440 changed files with 2705 additions and 1853 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Admin
class DashboardPolicy < AdminOnlyPolicy
def dump_docker?

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
class AdminOnlyPolicy < ApplicationPolicy
[:create?, :destroy?, :edit?, :index?, :new?, :show?, :update?].each do |action|
%i[create? destroy? edit? index? new? show? update?].each do |action|
define_method(action) { admin? }
end
end

View File

@ -1,9 +1,11 @@
# frozen_string_literal: true
class AdminOrAuthorPolicy < ApplicationPolicy
[:create?, :index?, :new?].each do |action|
%i[create? index? new?].each do |action|
define_method(action) { admin? || teacher? }
end
[:destroy?, :edit?, :show?, :update?].each do |action|
%i[destroy? edit? show? update?].each do |action|
define_method(action) { admin? || author? }
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationPolicy
def admin?
@user.admin?
@ -43,7 +45,7 @@ class ApplicationPolicy
return false
end
@user.study_groups.any?{|i| study_groups.include?(i) }
@user.study_groups.any? {|i| study_groups.include?(i) }
end
private :everyone_in_study_group
@ -59,7 +61,7 @@ class ApplicationPolicy
end
def require_user!
fail Pundit::NotAuthorizedError unless @user
raise Pundit::NotAuthorizedError unless @user
end
private :require_user!
@ -71,7 +73,7 @@ class ApplicationPolicy
end
def require_user!
fail Pundit::NotAuthorizedError unless @user
raise Pundit::NotAuthorizedError unless @user
end
private :require_user!
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module CodeOcean
class FilePolicy < AdminOrAuthorPolicy
def author?
@ -15,7 +17,7 @@ module CodeOcean
def create?
if @record.context.is_a?(Exercise)
admin? || author?
elsif @record.context.is_a?(Submission) and @record.context.exercise.allow_file_creation
elsif @record.context.is_a?(Submission) && @record.context.exercise.allow_file_creation
author?
else
no_one

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CodeharborLinkPolicy < ApplicationPolicy
def index?
false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CommentPolicy < ApplicationPolicy
def create?
everyone
@ -7,7 +9,7 @@ class CommentPolicy < ApplicationPolicy
everyone
end
[:new?, :destroy?, :update?, :edit?].each do |action|
%i[new? destroy? update? edit?].each do |action|
define_method(action) { admin? || author? }
end

View File

@ -1,3 +1,4 @@
class ConsumerPolicy < AdminOnlyPolicy
# frozen_string_literal: true
class ConsumerPolicy < AdminOnlyPolicy
end

View File

@ -1,3 +1,4 @@
class ErrorTemplateAttributePolicy < AdminOnlyPolicy
# frozen_string_literal: true
class ErrorTemplateAttributePolicy < AdminOnlyPolicy
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ErrorTemplatePolicy < AdminOnlyPolicy
def add_attribute?
admin?

View File

@ -1,7 +1,7 @@
class EventPolicy < AdminOnlyPolicy
# frozen_string_literal: true
class EventPolicy < AdminOnlyPolicy
def create?
everyone
end
end

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
class ExecutionEnvironmentPolicy < AdminOnlyPolicy
[:execute_command?, :shell?, :statistics?, :show?].each do |action|
%i[execute_command? shell? statistics? show?].each do |action|
define_method(action) { admin? || author? }
end

View File

@ -1,7 +1,7 @@
class ExerciseCollectionPolicy < AdminOnlyPolicy
# frozen_string_literal: true
class ExerciseCollectionPolicy < AdminOnlyPolicy
def statistics?
admin?
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ExternalUserPolicy < AdminOnlyPolicy
def index?
admin? || teacher?

View File

@ -1,7 +1,7 @@
class FileTemplatePolicy < AdminOnlyPolicy
# frozen_string_literal: true
class FileTemplatePolicy < AdminOnlyPolicy
def by_file_type?
everyone
end
end

View File

@ -1,3 +1,4 @@
class FileTypePolicy < AdminOnlyPolicy
# frozen_string_literal: true
class FileTypePolicy < AdminOnlyPolicy
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class InternalUserPolicy < AdminOnlyPolicy
def destroy?
super && !@record.admin?

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ProxyExercisePolicy < AdminOrAuthorPolicy
def batch_update?
admin?
@ -7,8 +9,8 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
admin? || teacher_in_study_group? || teacher? && @record.public? || author?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
define_method(action) { admin? || author?}
%i[clone? destroy? edit? update?].each do |action|
define_method(action) { admin? || author? }
end
[:reload?].each do |action|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class SearchPolicy < AdminOrAuthorPolicy
def batch_update?
admin?
@ -7,8 +9,8 @@ class SearchPolicy < AdminOrAuthorPolicy
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
define_method(action) { admin? || author?}
%i[clone? destroy? edit? update?].each do |action|
define_method(action) { admin? || author? }
end
[:reload?].each do |action|

View File

@ -1,7 +1,7 @@
class StatisticsPolicy < AdminOnlyPolicy
# frozen_string_literal: true
[:graphs?, :user_activity?, :user_activity_history?, :rfc_activity?, :rfc_activity_history?].each do |action|
class StatisticsPolicy < AdminOnlyPolicy
%i[graphs? user_activity? user_activity_history? rfc_activity? rfc_activity_history?].each do |action|
define_method(action) { admin? }
end
end

View File

@ -1,9 +1,11 @@
# frozen_string_literal: true
class StudyGroupPolicy < AdminOnlyPolicy
def index?
admin? || teacher?
end
[:show?, :destroy?, :edit?, :update?, :stream_la?].each do |action|
%i[show? destroy? edit? update? stream_la?].each do |action|
define_method(action) { admin? || @user.teacher? && @record.present? && @user.study_groups.exists?(@record.id) }
end

View File

@ -1,10 +1,13 @@
# frozen_string_literal: true
class SubmissionPolicy < ApplicationPolicy
def create?
everyone
end
# insights? is used in the flowr_controller.rb as we use it to authorize the user for a submission
[:download?, :download_file?, :render_file?, :run?, :score?, :show?, :statistics?, :stop?, :test?, :insights?].each do |action|
%i[download? download_file? render_file? run? score? show? statistics? stop? test?
insights?].each do |action|
define_method(action) { admin? || author? }
end
@ -12,7 +15,6 @@ class SubmissionPolicy < ApplicationPolicy
admin?
end
def show_study_group?
admin? || teacher_in_study_group?
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class SubscriptionPolicy < ApplicationPolicy
def create?
everyone

View File

@ -1,5 +1,6 @@
class TagPolicy < AdminOnlyPolicy
# frozen_string_literal: true
class TagPolicy < AdminOnlyPolicy
class Scope < Scope
def resolve
if @user.admin? || @user.teacher?
@ -9,5 +10,4 @@ class TagPolicy < AdminOnlyPolicy
end
end
end
end

View File

@ -1,5 +1,6 @@
class TipPolicy < AdminOnlyPolicy
# frozen_string_literal: true
class TipPolicy < AdminOnlyPolicy
class Scope < Scope
def resolve
if @user.admin? || @user.teacher?
@ -9,5 +10,4 @@ class TipPolicy < AdminOnlyPolicy
end
end
end
end

View File

@ -1,5 +1,6 @@
class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
# frozen_string_literal: true
class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
def create?
everyone
end
@ -7,5 +8,4 @@ class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
def new?
everyone
end
end