Skip to content

Commit b3dfd30

Browse files
committed
More review changes
1 parent 8dd9f8e commit b3dfd30

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Beacons
2+
class BaseController < ApplicationController
3+
before_action :redirect_contributors
4+
5+
private
6+
7+
def redirect_contributors
8+
redirect_to root_path, alert: "You don't have permission to access this page." unless Current.user&.is_admin?
9+
end
10+
end
11+
end

app/controllers/beacons_controller.rb renamed to app/controllers/beacons/beacons_controller.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
class BeaconsController < ApplicationController
2-
before_action :redirect_contributors
1+
class BeaconsController < Beacons::BaseController
32
before_action :set_beacon, only: %i[show edit update regenerate_key revoke_key]
3+
before_action :prepare_associations, only: %i[new edit]
44

55
def index
66
@beacons = Beacon.includes(:language, :region, :providers, :topics).order(created_at: :desc)
77
end
88

99
def new
10-
prepare_associations
10+
@beacon = Beacon.new
1111
end
1212

1313
def create
1414
success, @beacon, api_key = Beacons::Creator.new.call(beacon_params)
1515

1616
case Beacons::Creator.new.call(beacon_params)
17-
when [true, @beacon, api_key]
17+
when [ true, @beacon, api_key ]
1818
flash[:notice] = "Beacon was successfully provisioned. API Key: #{api_key}"
1919
redirect_to @beacon
20-
when [false, _, _]
20+
when [ false, _, _ ]
2121
prepare_associations
2222
render :new, status: :unprocessable_entity
2323
end
2424
end
2525

2626
def show; end
2727

28-
def edit
29-
prepare_associations
30-
end
28+
def edit; end
3129

3230
def update
3331
if @beacon.update(beacon_params)
@@ -74,8 +72,4 @@ def prepare_associations
7472
def beacon_params
7573
params.require(:beacon).permit(:name, :language_id, :region_id, provider_ids: [], topic_ids: [])
7674
end
77-
78-
def redirect_contributors
79-
redirect_to root_path, alert: "You don't have permission to access this page." unless Current.user&.is_admin?
80-
end
8175
end

0 commit comments

Comments
 (0)