Skip to content

Commit e543124

Browse files
committed
Fix policy problems
1 parent 6bd3958 commit e543124

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

app/graphql/types/node_function_type.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ module Types
44
class NodeFunctionType < Types::BaseObject
55
description 'Represents a Node Function'
66

7-
# authorize :read_flow TODO problem is node function doesnt have access to the project, only the runtime
8-
# see NodeFunctionPolicy
7+
authorize :read_flow
98

109
field :next_node, Types::NodeFunctionType, null: true, description: 'The next Node Function in the flow'
1110
field :parameters, Types::NodeParameterType.connection_type, null: false, method: :node_parameters,

app/models/node_function.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,36 @@ class NodeFunction < ApplicationRecord
44
belongs_to :runtime_function, class_name: 'RuntimeFunctionDefinition'
55
belongs_to :next_node, class_name: 'NodeFunction', optional: true
66

7+
has_one :previous_node, class_name: 'NodeFunction', foreign_key: :next_node_id, inverse_of: :next_node
8+
79
has_many :node_parameter_values, class_name: 'NodeParameter', inverse_of: :function_value
810
has_many :node_parameters, class_name: 'NodeParameter', inverse_of: :node_function
911
has_many :flows, class_name: 'Flow', inverse_of: :starting_node
1012

1113
validate :validate_recursion, if: :next_node_changed?
1214

15+
def resolve_flow
16+
flow = Flow.find_by(starting_node: self)
17+
if flow.present?
18+
return flow
19+
end
20+
21+
NodeFunction.where(next_node: self).each do |node|
22+
while node.previous_node.present?
23+
node = node.previous_node
24+
if node.flow.present?
25+
return node.flow
26+
end
27+
end
28+
end
29+
30+
NodeParameter.where(function_value: self).each do |param|
31+
if param.node_function.flow.present?
32+
return param.node_function.resolve_flow
33+
end
34+
end
35+
end
36+
1337
def validate_recursion
1438
current_node = self
1539
until current_node.next_node.nil?

app/policies/namespace_policy.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class NamespacePolicy < BasePolicy
2020
enable :read_namespace_member
2121
enable :read_namespace_member_role
2222
enable :read_namespace_role
23-
enable :read_flow
2423
end
2524

2625
namespace_resolver { |namespace| namespace }

app/policies/namespace_project_policy.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class NamespaceProjectPolicy < BasePolicy
99

1010
rule { can_create_projects }.enable :read_namespace_project
1111

12+
rule { can?(:has_access) }.policy do
13+
enable :read_flow
14+
end
15+
1216
customizable_permission :assign_project_runtimes
1317
customizable_permission :read_namespace_project
1418
customizable_permission :update_namespace_project

app/policies/node_function_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
class NodeFunctionPolicy < BasePolicy
4-
delegate { subject.runtime_function }
4+
delegate { subject.resolve_flow }
55
end

spec/models/flow_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
it { is_expected.to belong_to(:starting_node).class_name('NodeFunction') }
1212
it { is_expected.to belong_to(:input_type).class_name('DataType').optional }
1313
it { is_expected.to belong_to(:return_type).class_name('DataType').optional }
14+
15+
it { is_expected.to have_many(:flow_settings) }
1416
end
1517
end

spec/requests/graphql/mutation/namespace/projects/flows/create_mutation_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
id
1919
parameters {
2020
count
21+
nodes {
22+
id
23+
}
2124
}
2225
}
2326
settings {
@@ -74,11 +77,14 @@
7477
context 'when user has the permission' do
7578
before do
7679
stub_allowed_ability(NamespaceProjectPolicy, :create_flows, user: current_user, subject: project)
80+
stub_allowed_ability(NamespaceProjectPolicy, :read_flow, user: current_user, subject: project)
7781
end
7882

7983
it 'creates namespace project' do
8084
mutate!
8185

86+
p parsed_response
87+
8288
created_flow_id = graphql_data_at(:namespaces_projects_flows_create, :flow, :id)
8389
expect(created_flow_id).to be_present
8490
flow = SagittariusSchema.object_from_id(created_flow_id)

0 commit comments

Comments
 (0)