Skip to content

Commit 37de76c

Browse files
committed
Make advisory api same as token api
1 parent fe0ece3 commit 37de76c

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

app/controllers/api/v1/advisories_controller.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController
44
before_action :load_advisory, only: %i(show update attach_build_list destroy)
55

66
def index
7-
authorize :advisory
7+
authorize :advisory_api
88
@advisories = Advisory.all.paginate(paginate_params)
99
end
1010

1111
def show
12+
authorize :advisory_api
1213
end
1314

1415
def create
15-
authorize :advisory
16+
authorize :advisory_api
1617
projects = JSON.parse(request.body.string).try(:[], 'advisory').try(:[], 'projects')
1718
result = AdvisoryService::Create.call(
1819
advisory_params: advisory_params,
@@ -26,13 +27,12 @@ def create
2627
end
2728

2829
def update
30+
authorize :advisory_api
2931
update_subject @advisory
3032
end
3133

3234
def destroy
33-
@advisory.platforms.each do |pl|
34-
authorize pl, :local_admin_manage?
35-
end
35+
authorize :advisory_api
3636
destroy_subject @advisory
3737
end
3838

@@ -43,8 +43,8 @@ def advisory_params
4343
end
4444

4545
def load_advisory
46-
@advisory = Advisory.find_by(advisory_id: params[:id]) if params[:id]
47-
authorize @advisory if @advisory
46+
@advisory = Advisory.find_by(advisory_id: params[:id])
47+
raise ActiveRecord::RecordNotFound unless @advisory
4848
end
4949

5050
end

app/policies/advisory_api_policy.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class AdvisoryApiPolicy < ApplicationPolicy
2+
3+
def index?
4+
user.access_to_advisories_api
5+
end
6+
7+
alias_method :show?, :index?
8+
alias_method :create?, :index?
9+
alias_method :update?, :index?
10+
alias_method :destroy?, :index?
11+
12+
def permitted_attributes
13+
%i(
14+
update_type
15+
description
16+
references
17+
)
18+
end
19+
20+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddAccessToAdvisoriesApiToUsers < ActiveRecord::Migration
2+
def change
3+
add_column :users, :access_to_advisories_api, :bool, default: false
4+
end
5+
end

db/schema.rb

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20220605132041) do
14+
ActiveRecord::Schema.define(version: 20230110075556) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -237,38 +237,39 @@
237237
end
238238

239239
create_table "users", force: :cascade do |t|
240-
t.string "name", :limit=>255
241-
t.string "email", :limit=>255, :default=>"", :null=>false, :index=>{:name=>"index_users_on_email", :unique=>true}
242-
t.string "encrypted_password", :limit=>128, :default=>"", :null=>false
243-
t.string "reset_password_token", :limit=>255, :index=>{:name=>"index_users_on_reset_password_token", :unique=>true}
240+
t.string "name", :limit=>255
241+
t.string "email", :limit=>255, :default=>"", :null=>false, :index=>{:name=>"index_users_on_email", :unique=>true}
242+
t.string "encrypted_password", :limit=>128, :default=>"", :null=>false
243+
t.string "reset_password_token", :limit=>255, :index=>{:name=>"index_users_on_reset_password_token", :unique=>true}
244244
t.datetime "reset_password_sent_at"
245245
t.datetime "remember_created_at"
246246
t.datetime "created_at"
247247
t.datetime "updated_at"
248248
t.text "ssh_key"
249-
t.string "uname", :limit=>255, :index=>{:name=>"index_users_on_uname", :unique=>true}
250-
t.string "role", :limit=>255
251-
t.string "language", :limit=>255, :default=>"en"
252-
t.integer "own_projects_count", :default=>0, :null=>false
249+
t.string "uname", :limit=>255, :index=>{:name=>"index_users_on_uname", :unique=>true}
250+
t.string "role", :limit=>255
251+
t.string "language", :limit=>255, :default=>"en"
252+
t.integer "own_projects_count", :default=>0, :null=>false
253253
t.text "professional_experience"
254-
t.string "site", :limit=>255
255-
t.string "company", :limit=>255
256-
t.string "location", :limit=>255
257-
t.string "avatar_file_name", :limit=>255
258-
t.string "avatar_content_type", :limit=>255
254+
t.string "site", :limit=>255
255+
t.string "company", :limit=>255
256+
t.string "location", :limit=>255
257+
t.string "avatar_file_name", :limit=>255
258+
t.string "avatar_content_type", :limit=>255
259259
t.integer "avatar_file_size"
260260
t.datetime "avatar_updated_at"
261-
t.integer "failed_attempts", :default=>0
262-
t.string "unlock_token", :limit=>255, :index=>{:name=>"index_users_on_unlock_token", :unique=>true}
261+
t.integer "failed_attempts", :default=>0
262+
t.string "unlock_token", :limit=>255, :index=>{:name=>"index_users_on_unlock_token", :unique=>true}
263263
t.datetime "locked_at"
264-
t.string "confirmation_token", :limit=>255, :index=>{:name=>"index_users_on_confirmation_token", :unique=>true}
264+
t.string "confirmation_token", :limit=>255, :index=>{:name=>"index_users_on_confirmation_token", :unique=>true}
265265
t.datetime "confirmed_at"
266266
t.datetime "confirmation_sent_at"
267-
t.string "authentication_token", :limit=>255, :index=>{:name=>"index_users_on_authentication_token"}
268-
t.integer "build_priority", :default=>50
269-
t.boolean "sound_notifications", :default=>true
270-
t.boolean "hide_email", :default=>true, :null=>false
271-
t.boolean "access_to_token_api", :default=>false
267+
t.string "authentication_token", :limit=>255, :index=>{:name=>"index_users_on_authentication_token"}
268+
t.integer "build_priority", :default=>50
269+
t.boolean "sound_notifications", :default=>true
270+
t.boolean "hide_email", :default=>true, :null=>false
271+
t.boolean "access_to_token_api", :default=>false
272+
t.boolean "access_to_advisories_api", :default=>false
272273
end
273274

274275
create_table "invites", force: :cascade do |t|

0 commit comments

Comments
 (0)