-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10256 from intrip/refactor_require_login_my_tasks
Replace `require_login` with Pundit in Webui::Users::TasksController
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
module Webui | ||
module Users | ||
class TasksController < WebuiController | ||
before_action :require_login | ||
# TODO: Remove this when we'll refactor kerberos_auth | ||
before_action :kerberos_auth | ||
before_action -> { authorize([:users, :task]) } | ||
|
||
after_action :verify_authorized | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Users | ||
class TaskPolicy < ApplicationPolicy | ||
def initialize(user, record, opts = {}) | ||
super(user, record, opts.merge(ensure_logged_in: true)) | ||
end | ||
|
||
def index? | ||
true | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
src/api/spec/controllers/webui/users/tasks_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Webui::Users::TasksController do | ||
describe 'GET #index' do | ||
it_behaves_like 'require logged in user' do | ||
let(:method) { :get } | ||
let(:action) { :index } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Users::TaskPolicy do | ||
let(:user) { create(:user) } | ||
let(:user_nobody) { build(:user_nobody) } | ||
|
||
subject { described_class } | ||
|
||
permissions :index? do | ||
it { is_expected.to permit(user, [:users, :task]) } | ||
end | ||
|
||
it "doesn't permit anonymous user" do | ||
expect { described_class.new(user_nobody, [:users, :task]) } | ||
.to raise_error(an_instance_of(Pundit::NotAuthorizedError).and(having_attributes(reason: :anonymous_user))) | ||
end | ||
end |