Skip to content

Commit cbc0c20

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

19 files changed

+93
-45
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@ 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+
return flow if flow.present?
18+
19+
NodeFunction.where(next_node: self).find_each do |node|
20+
while node.previous_node.present?
21+
node = node.previous_node
22+
return node.flow if node.flow.present?
23+
end
24+
end
25+
26+
NodeParameter.where(function_value: self).find_each do |param|
27+
return param.node_function.resolve_flow if param.node_function.flow.present?
28+
end
29+
end
30+
1331
def validate_recursion
1432
current_node = self
1533
until current_node.next_node.nil?

app/policies/namespace_policy.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class NamespacePolicy < BasePolicy
2121
enable :read_namespace_member_role
2222
enable :read_namespace_role
2323
enable :read_flow
24+
enable :read_runtime
25+
enable :read_datatype
26+
enable :read_flow_type
27+
enable :read_flow_type_setting
2428
end
2529

2630
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

docs/graphql/enum/namespaceroleability.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Represents abilities that can be granted to roles in namespaces.
1010
| `ASSIGN_PROJECT_RUNTIMES` | Allows to assign runtimes to a project in the namespace |
1111
| `ASSIGN_ROLE_ABILITIES` | Allows to change the abilities of a namespace role |
1212
| `ASSIGN_ROLE_PROJECTS` | Allows to change the assigned projects of a namespace role |
13-
| `CREATE_FLOWS` | Allows to create flows in the namespace |
13+
| `CREATE_FLOWS` | Allows to create flows in the project |
1414
| `CREATE_NAMESPACE_LICENSE` | Allows to create a license for the namespace |
1515
| `CREATE_NAMESPACE_PROJECT` | Allows to create a project in the namespace |
1616
| `CREATE_NAMESPACE_ROLE` | Allows the creation of roles in a namespace |
1717
| `CREATE_RUNTIME` | Allows to create a runtime globally or for the namespace |
18-
| `DELETE_FLOWS` | Allows to delete flows in the namespace |
18+
| `DELETE_FLOWS` | Allows to delete flows in the project |
1919
| `DELETE_MEMBER` | Allows to remove members of a namespace |
2020
| `DELETE_NAMESPACE_LICENSE` | Allows to delete the license of the namespace |
2121
| `DELETE_NAMESPACE_PROJECT` | Allows to delete the project of the namespace |
@@ -24,10 +24,11 @@ Represents abilities that can be granted to roles in namespaces.
2424
| `DELETE_RUNTIME` | Allows to delete a runtime |
2525
| `INVITE_MEMBER` | Allows to invite new members to a namespace |
2626
| `NAMESPACE_ADMINISTRATOR` | Allows to perform any action in the namespace |
27+
| `READ_FLOW` | Allows to read flows in the project |
2728
| `READ_NAMESPACE_LICENSE` | Allows to read the license of the namespace |
2829
| `READ_NAMESPACE_PROJECT` | Allows to read the project of the namespace |
2930
| `ROTATE_RUNTIME_TOKEN` | Allows to regenerate a runtime token |
30-
| `UPDATE_FLOWS` | Allows to update flows in the namespace |
31+
| `UPDATE_FLOWS` | Allows to update flows in the project |
3132
| `UPDATE_NAMESPACE_PROJECT` | Allows to update the project of the namespace |
3233
| `UPDATE_NAMESPACE_ROLE` | Allows to update the namespace role |
3334
| `UPDATE_ORGANIZATION` | Allows to update the organization |

docs/graphql/input_object/flowinput.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ Input type for creating or updating a flow
88

99
| Name | Type | Description |
1010
|------|------|-------------|
11-
| `inputType` | [`DataTypeID`](../scalar/datatypeid.md) | The ID of the input data type |
12-
| `returnType` | [`DataTypeID`](../scalar/datatypeid.md) | The ID of the return data type |
1311
| `settings` | [`[FlowSettingInput!]`](../input_object/flowsettinginput.md) | The settings of the flow |
1412
| `startingNode` | [`NodeFunctionInput!`](../input_object/nodefunctioninput.md) | The starting node of the flow |
1513
| `type` | [`FlowTypeID!`](../scalar/flowtypeid.md) | The identifier of the flow type |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: namespacesProjectsFlowsDelete
3+
---
4+
5+
Deletes a namespace project.
6+
7+
## Arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `clientMutationId` | [`String`](../scalar/string.md) | A unique identifier for the client performing the mutation. |
12+
| `flowId` | [`FlowID!`](../scalar/flowid.md) | The id of the flow which will be deleted |
13+
14+
## Fields
15+
16+
| Name | Type | Description |
17+
|------|------|-------------|
18+
| `clientMutationId` | [`String`](../scalar/string.md) | A unique identifier for the client performing the mutation. |
19+
| `errors` | [`[Error!]!`](../union/error.md) | Errors encountered during execution of the mutation. |
20+
| `flow` | [`Flow`](../object/flow.md) | The deleted flow. |

docs/graphql/object/flow.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Represents a flow
99
| Name | Type | Description |
1010
|------|------|-------------|
1111
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created |
12-
| `flowId` | [`FlowID!`](../scalar/flowid.md) | The global ID of the flow |
1312
| `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow |
1413
| `inputType` | [`DataType`](../object/datatype.md) | The input data type of the flow |
1514
| `returnType` | [`DataType`](../object/datatype.md) | The return data type of the flow |

docs/graphql/object/flowsetting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Represents a flow setting
99
| Name | Type | Description |
1010
|------|------|-------------|
1111
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this FlowSetting was created |
12-
| `databaseId` | [`FlowSettingID!`](../scalar/flowsettingid.md) | The global ID of the flow setting |
12+
| `flowSettingId` | [`String!`](../scalar/string.md) | The identifier of the flow setting |
1313
| `id` | [`FlowSettingID!`](../scalar/flowsettingid.md) | Global ID of this FlowSetting |
1414
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this FlowSetting was last updated |
1515
| `value` | [`JSON!`](../scalar/json.md) | The value of the flow setting |

docs/graphql/object/nodefunction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Represents a Node Function
99
| Name | Type | Description |
1010
|------|------|-------------|
1111
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this NodeFunction was created |
12-
| `function` | [`NodeFunctionDefinition!`](../object/nodefunctiondefinition.md) | The definition of the Node Function |
1312
| `id` | [`NodeFunctionID!`](../scalar/nodefunctionid.md) | Global ID of this NodeFunction |
1413
| `nextNode` | [`NodeFunction`](../object/nodefunction.md) | The next Node Function in the flow |
1514
| `parameters` | [`NodeParameterConnection!`](../object/nodeparameterconnection.md) | The parameters of the Node Function |
15+
| `runtimeFunction` | [`RuntimeFunctionDefinition!`](../object/runtimefunctiondefinition.md) | The definition of the Node Function |
1616
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this NodeFunction was last updated |
1717

docs/graphql/object/nodefunctiondefinition.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/graphql/object/nodeparameter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Represents a Node parameter
99
| Name | Type | Description |
1010
|------|------|-------------|
1111
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this NodeParameter was created |
12-
| `definition` | [`NodeParameterDefinition!`](../object/nodeparameterdefinition.md) | The definition of the parameter |
1312
| `id` | [`NodeParameterID!`](../scalar/nodeparameterid.md) | Global ID of this NodeParameter |
13+
| `runtimeParameter` | [`RuntimeParameterDefinition!`](../object/runtimeparameterdefinition.md) | The definition of the parameter |
1414
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this NodeParameter was last updated |
1515
| `value` | [`NodeParameterValue`](../union/nodeparametervalue.md) | The value of the parameter |
1616

docs/graphql/object/nodeparameterdefinition.md

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: RuntimeFunctionDefinition
3+
---
4+
5+
Represents a Node Function definition
6+
7+
## Fields without arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeFunctionDefinition was created |
12+
| `id` | [`RuntimeParameterDefinitionID!`](../scalar/runtimeparameterdefinitionid.md) | Global ID of this RuntimeFunctionDefinition |
13+
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeFunctionDefinition was last updated |
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: RuntimeParameterDefinition
3+
---
4+
5+
Represents a Node parameter definition
6+
7+
## Fields without arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `createdAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeParameterDefinition was created |
12+
| `id` | [`RuntimeParameterDefinitionID!`](../scalar/runtimeparameterdefinitionid.md) | Global ID of this RuntimeParameterDefinition |
13+
| `updatedAt` | [`Time!`](../scalar/time.md) | Time when this RuntimeParameterDefinition was last updated |
14+

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: 4 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,6 +77,7 @@
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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
context 'when user has permission' do
3737
before do
3838
stub_allowed_ability(NamespaceProjectPolicy, :delete_flows, user: current_user,
39-
subject: namespace_project)
39+
subject: namespace_project)
4040
stub_allowed_ability(NamespaceProjectPolicy, :read_flow, user: current_user,
41-
subject: namespace_project)
41+
subject: namespace_project)
4242
end
4343

4444
it 'deletes flow' do
@@ -71,7 +71,8 @@
7171
mutate!
7272

7373
expect(graphql_data_at(:namespaces_projects_flows_delete, :flow)).to be_nil
74-
expect(graphql_data_at(:namespaces_projects_flows_delete, :errors)).to include({ 'message' => 'missing_permission' })
74+
expect(graphql_data_at(:namespaces_projects_flows_delete,
75+
:errors)).to include({ 'message' => 'missing_permission' })
7576
end
7677
end
7778
end

0 commit comments

Comments
 (0)