Skip to content

Commit ab8b0dc

Browse files
committed
linter fixes
1 parent bbffbd5 commit ab8b0dc

File tree

11 files changed

+34
-19
lines changed

11 files changed

+34
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the d
9999
### 9. Abilities with CanCanCan
100100
[CanCanCan](https://github.com/CanCanCommunity/cancancan) is an authorization library for Ruby and Ruby on Rails which restricts what resources a given user is allowed to access. We combine this gem with a `role` field defined on user model.
101101

102+
Start defining your abilities under `app/models/aility.rb`.
103+
102104
### 10. Rails Admin
103105
To access the data of your application you can access the [rails_admin](https://github.com/sferik/rails_admin) dashboard under route `/admin`. It's currently only allowed for users with role superadmin.
104106

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Base controlller for application
34
class ApplicationController < ActionController::Base
45
force_ssl if: :ssl_configured?
56

app/controllers/pages_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# A controller to handle static pages served from backend
14
class PagesController < ApplicationController
25
def blank
3-
head 200, content_type: "text/html"
6+
head 200, content_type: 'text/html'
47
end
5-
end
8+
end

app/models/ability.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
# Defines abilities for user
4+
# rubocop:disable Style/GuardClause
15
class Ability
26
include CanCan::Ability
37

@@ -6,16 +10,17 @@ def initialize(user)
610

711
alias_action :create, :read, :update, :destroy, to: :crud
812

9-
unless user.new_record?
10-
if user.superadmin?
11-
can :access, :rails_admin # grant access to rails_admin
12-
can :manage, :all # admins can manage all objects
13-
elsif user.admin?
14-
# can :crud, Survey::QuestionAnswer # user can crud all question answers
15-
end
13+
return if user.new_record?
14+
15+
if user.superadmin?
16+
can :access, :rails_admin # grant access to rails_admin
17+
can :manage, :all # admins can manage all objects
18+
# elsif user.admin?
19+
# can :crud, Survey::QuestionAnswer # user can crud all question answers
1620
end
1721

1822
# See the wiki for details:
1923
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
2024
end
2125
end
26+
# rubocop:enable Style/GuardClause

app/models/user.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# User model to access application
44
class User < ApplicationRecord
5-
65
# Include default devise modules. Others available are:
76
# :confirmable, :timeoutable, :trackable and :omniauthable
87
devise :database_authenticatable,
@@ -35,7 +34,7 @@ def status_color
3534
return 'warning' if role == 'admin'
3635
return 'danger' if role == 'superadmin'
3736

38-
return 'primary'
37+
'primary'
3938
end
4039

4140
private
@@ -45,13 +44,16 @@ def setup_new_user
4544
end
4645

4746
# :nocov:
47+
# rubocop:disable Metrics/BlockLength
4848
rails_admin do
4949
weight 10
5050
navigation_icon 'fa fa-user-circle'
5151

5252
configure :role do
5353
pretty_value do # used in list view columns and show views, defaults to formatted_value for non-association fields
54-
bindings[:view].content_tag(:span, User.human_attribute_name(value), class: "label label-#{bindings[:object].status_color}")
54+
bindings[:view].tag.span(
55+
User.human_attribute_name(value), class: "label label-#{bindings[:object].status_color}"
56+
)
5557
end
5658
export_value do
5759
User.human_attribute_name(value)
@@ -60,7 +62,7 @@ def setup_new_user
6062

6163
configure :email do
6264
pretty_value do
63-
bindings[:view].link_to(value, 'mailto:' + value)
65+
bindings[:view].link_to(value, "mailto:#{value}")
6466
end
6567
export_value do
6668
value
@@ -94,5 +96,6 @@ def setup_new_user
9496
field :last_sign_in_at
9597
end
9698
end
99+
# rubocop:enable Metrics/BlockLength
97100
# :nocov:
98101
end

config/application.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,5 @@ class Application < Rails::Application
4242
# Skip views, helpers and assets when generating a new resource.
4343

4444
config.time_zone = 'Berlin'
45-
46-
47-
4845
end
4946
end

config/environments/development.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
# Use an evented file watcher to asynchronously detect changes in source code,
5252
# routes, locales, etc. This feature depends on the listen gem.
5353
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
54-
55-
config.action_mailer.default_url_options = { host: ENV['DEFAULT_URL'] }
5654

55+
config.action_mailer.default_url_options = { host: ENV['DEFAULT_URL'] }
5756
end

config/initializers/generators.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
Rails.application.config.generators do |g|
24
g.orm :active_record, primary_key_type: :uuid
35
g.orm :active_record, foreign_key_type: :uuid

config/initializers/locale.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Whitelist locales available for the application
24
I18n.available_locales = %i[en de]
35

config/initializers/rails_admin.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
RailsAdmin.config do |config|
24
### Popular gems integration
35

0 commit comments

Comments
 (0)