Skip to content

Commit e21e1ac

Browse files
author
Christopher Talib
authored
Merge pull request #289 from tosdr/sec/access-modification
[sec] adding a test for curator status
2 parents 798e78d + 540ad49 commit e21e1ac

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

app/controllers/points_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class PointsController < ApplicationController
22
before_action :authenticate_user!, except: [:index, :show]
3+
before_action :set_curator, except: [:index, :show]
34
before_action :set_point, only: [:show, :edit, :featured, :update, :destroy]
45
before_action :points_get, only: [:index]
56

@@ -100,4 +101,10 @@ def points_get
100101
@points = Point.all.where(status: "pending")
101102
end
102103
end
104+
105+
def set_curator
106+
unless current_user.curator?
107+
render :file => "public/401.html", :status => :unauthorized
108+
end
109+
end
103110
end

app/controllers/reasons_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class ReasonsController < ApplicationController
22
before_action :authenticate_user!, except: [:index, :show]
3+
before_action :set_curator, except: [:index, :show]
34
before_action :set_point, only: [:new, :create]
45
before_action :set_admin
56
def new
@@ -38,7 +39,14 @@ def set_point
3839
def reason_params
3940
params.require(:reason).permit(:content)
4041
end
42+
4143
def point_params
4244
params.require(:point).permit(:status)
4345
end
46+
47+
def set_curator
48+
unless current_user.curator?
49+
render :file => "public/401.html", :status => :unauthorized
50+
end
51+
end
4452
end

app/controllers/services_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class ServicesController < ApplicationController
22
before_action :authenticate_user!, except: [:index, :show]
3+
before_action :set_curator, except: [:index, :show]
34
before_action :set_service, only: [:show, :edit, :update, :destroy]
45

56
def index
@@ -74,4 +75,9 @@ def service_params
7475
params.require(:service).permit(:name, :url, :query)
7576
end
7677

78+
def set_curator
79+
unless current_user.curator?
80+
render :file => "public/401.html", :status => :unauthorized
81+
end
82+
end
7783
end

app/controllers/topics_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class TopicsController < ApplicationController
22
before_action :authenticate_user!, except: [:index, :show]
3+
before_action :set_curator, except: [:index, :show]
34
before_action :set_topic, only: [:show, :edit, :update, :destroy]
45

56
def index
@@ -61,4 +62,9 @@ def topic_params
6162
params.require(:topic).permit(:title, :subtitle, :description, :query, :privacy_related)
6263
end
6364

65+
def set_curator
66+
unless current_user.curator?
67+
render :file => "public/401.html", :status => :unauthorized
68+
end
69+
end
6470
end

public/401.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body style="background-color: #FdFdFd;color: #F89300;text-align: center;">
4+
<!-- This file lives in public/401.html -->
5+
<h1>Uh-Oh!</h1>
6+
<h2>You are not authorized to do this!</h2>
7+
<div class="back-home" style="margin-top: 50px;margin-bottom: 10px;">
8+
<a href="/" class="btn" style="margin-top: 30px;background-color: #49A347;border-radius: 50px;color: white;font-weight: bold;padding: 10px 20px;">
9+
Back Home</a>
10+
</div>
11+
<p>
12+
<a href="https://github.com/tosdr/phoenix/issues/" style="margin: 0;text-decoration: none;color: grey;">Open an issue on Github</a>
13+
</p>
14+
<p>
15+
<a href="mailto:[email protected]" style="margin: 0;text-decoration: none;color: grey;">Contact us</a>
16+
</p>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)