Move method #approved_liquid_tags to user service (#10663)
This commit is contained in:
parent
511496c593
commit
120bd7940f
3 changed files with 32 additions and 15 deletions
|
|
@ -18,8 +18,6 @@ class ArticlesController < ApplicationController
|
|||
rowspan size span src start strong title value width
|
||||
].freeze
|
||||
|
||||
RESTRICTED_LIQUID_TAGS = [UserSubscriptionTag].freeze
|
||||
|
||||
def feed
|
||||
skip_authorization
|
||||
|
||||
|
|
@ -70,7 +68,7 @@ class ArticlesController < ApplicationController
|
|||
@version = @article.has_frontmatter? ? "v1" : "v2"
|
||||
@user = @article.user
|
||||
@organizations = @user&.organizations
|
||||
set_user_approved_liquid_tags
|
||||
@user_approved_liquid_tags = Users::ApprovedLiquidTags.call(@user)
|
||||
end
|
||||
|
||||
def manage
|
||||
|
|
@ -213,18 +211,7 @@ class ArticlesController < ApplicationController
|
|||
@organizations = @user&.organizations
|
||||
@tag = Tag.find_by(name: params[:template])
|
||||
@prefill = params[:prefill].to_s.gsub("\\n ", "\n").gsub("\\n", "\n")
|
||||
set_user_approved_liquid_tags
|
||||
end
|
||||
|
||||
def set_user_approved_liquid_tags
|
||||
@user_approved_liquid_tags =
|
||||
if @user
|
||||
RESTRICTED_LIQUID_TAGS.filter_map do |liquid_tag|
|
||||
liquid_tag if liquid_tag::VALID_ROLES.any? { |role| @user.has_role?(*Array(role)) }
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
@user_approved_liquid_tags = Users::ApprovedLiquidTags.call(@user)
|
||||
end
|
||||
|
||||
def handle_user_or_organization_feed
|
||||
|
|
|
|||
13
app/services/users/approved_liquid_tags.rb
Normal file
13
app/services/users/approved_liquid_tags.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module Users
|
||||
module ApprovedLiquidTags
|
||||
RESTRICTED_LIQUID_TAGS = [UserSubscriptionTag].freeze
|
||||
|
||||
def self.call(user)
|
||||
return [] unless user
|
||||
|
||||
RESTRICTED_LIQUID_TAGS.filter_map do |liquid_tag|
|
||||
liquid_tag if liquid_tag::VALID_ROLES.any? { |role| user.has_role?(*Array(role)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/services/users/approved_liquid_tags_spec.rb
Normal file
17
spec/services/users/approved_liquid_tags_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Users::ApprovedLiquidTags, type: :service do
|
||||
subject { described_class.call(user) }
|
||||
|
||||
context "when user is admin" do
|
||||
let(:user) { create(:user, :admin) }
|
||||
|
||||
it { is_expected.to match([UserSubscriptionTag]) }
|
||||
end
|
||||
|
||||
context "when user has no role" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it { is_expected.to be_empty }
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue