WIP
Dieser Commit ist enthalten in:
Ursprung
538d618ff3
Commit
d9d4c7d8fa
3 geänderte Dateien mit 40 neuen und 0 gelöschten Zeilen
33
lib/custom_wizard/guardian.rb
Normale Datei
33
lib/custom_wizard/guardian.rb
Normale Datei
|
@ -0,0 +1,33 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
class CustomWizard::Guardian
|
||||||
|
def initialize(user)
|
||||||
|
@user = user
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_edit_topic?(topic)
|
||||||
|
creating_wizard = topic.wizard_created.presence
|
||||||
|
return false unless creating_wizard
|
||||||
|
|
||||||
|
wizard_builder = CustomWizard::Builder.new(creating_wizard, @user)
|
||||||
|
wizard = wizard_builder.build
|
||||||
|
wizard_actions = wizard.actions
|
||||||
|
return false if wizard_actions.empty?
|
||||||
|
|
||||||
|
create_topic_action = wizard_actions.find do |action|
|
||||||
|
action['type'] === 'create_topic'
|
||||||
|
end
|
||||||
|
|
||||||
|
return wizard_can_create_topic_on_category?(action, topic)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def wizard_can_create_topic_on_category?(action, topic)
|
||||||
|
return false unless topic.category.present?
|
||||||
|
|
||||||
|
category = CustomWizard::Mapper.new(
|
||||||
|
inputs: action['category'],
|
||||||
|
data:
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -86,6 +86,7 @@ after_initialize do
|
||||||
../lib/custom_wizard/submission.rb
|
../lib/custom_wizard/submission.rb
|
||||||
../lib/custom_wizard/template.rb
|
../lib/custom_wizard/template.rb
|
||||||
../lib/custom_wizard/wizard.rb
|
../lib/custom_wizard/wizard.rb
|
||||||
|
../lib/custom_wizard/guardian.rb
|
||||||
../lib/custom_wizard/api/api.rb
|
../lib/custom_wizard/api/api.rb
|
||||||
../lib/custom_wizard/api/authorization.rb
|
../lib/custom_wizard/api/authorization.rb
|
||||||
../lib/custom_wizard/api/endpoint.rb
|
../lib/custom_wizard/api/endpoint.rb
|
||||||
|
|
6
spec/components/custom_wizard/guardian_spec.rb
Normale Datei
6
spec/components/custom_wizard/guardian_spec.rb
Normale Datei
|
@ -0,0 +1,6 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
require_relative '../../plugin_helper'
|
||||||
|
|
||||||
|
describe CustomWizard::Guardian do
|
||||||
|
|
||||||
|
end
|
Laden …
In neuem Issue referenzieren