decidim-api 0.28.5 → 0.29.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/packs/entrypoints/decidim_api_docs.scss +1 -2
- data/app/packs/entrypoints/decidim_api_graphiql.js +50 -36
- data/app/views/decidim/api/documentation/show.html.erb +1 -1
- data/app/views/layouts/decidim/api/documentation.html.erb +1 -1
- data/config/routes.rb +1 -1
- data/decidim-api.gemspec +4 -7
- data/lib/decidim/api/graphiql/config.rb +1 -1
- data/lib/decidim/api/test/component_context.rb +0 -435
- data/lib/decidim/api/test/shared_examples/statistics_examples.rb +2 -3
- data/lib/decidim/api/test/type_context.rb +3 -2
- data/lib/decidim/api/types/base_object.rb +0 -70
- data/lib/decidim/api/version.rb +1 -1
- metadata +19 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4f9bdaae8d166f02a55ec472fe0e400d2046f6cb38713381466c572e5f17c5b
|
4
|
+
data.tar.gz: 1b0c10c1c0e0ef7c8661465ace0d185d914173475bf33f6ec6fcb04f03bf626e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57da850dc9496e413f1c7c033a51bedb4258414a426bada0e4f41b986ed1cca6d06fc6b5b5f0707f0eaf854b5c802590c3107564fbd79eff04db9fb16873aed4
|
7
|
+
data.tar.gz: 2293c845d89f6ffc9662e67edccf170ae02e4639915b18df8b8cda8441bf9e4375551ee2b492df36be26a97b8b4f7d6ec863a7e5294937c1442cae3215a630ac
|
@@ -1,85 +1,100 @@
|
|
1
|
-
/* eslint-disable require-jsdoc */
|
1
|
+
/* eslint-disable require-jsdoc, react/no-deprecated */
|
2
2
|
|
3
3
|
import "entrypoints/decidim_api_graphiql.scss";
|
4
4
|
// Styles from node_modules/graphiql/graphiql.css
|
5
5
|
// It needs to be done in JS because postcss-import does not find files in node_modules/
|
6
|
-
import "graphiql/graphiql.css"
|
6
|
+
import "graphiql/graphiql.css";
|
7
7
|
|
8
8
|
import React from "react";
|
9
|
-
import
|
9
|
+
import { createRoot } from "react-dom/client";
|
10
10
|
|
11
|
-
import GraphiQL from "graphiql";
|
12
|
-
import Configuration from "src/decidim/configuration"
|
11
|
+
import { GraphiQL } from "graphiql"; // eslint-disable-line no-unused-vars
|
12
|
+
import Configuration from "src/decidim/configuration";
|
13
13
|
|
14
14
|
window.Decidim = window.Decidim || {};
|
15
|
-
window.Decidim.config = new Configuration()
|
15
|
+
window.Decidim.config = new Configuration();
|
16
16
|
|
17
17
|
let parameters = {};
|
18
18
|
|
19
19
|
// Parse the search string to get url parameters.
|
20
20
|
const search = window.location.search;
|
21
|
-
search.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
search.
|
22
|
+
substr(1).
|
23
|
+
split("&").
|
24
|
+
forEach(function (entry) {
|
25
|
+
let eq = entry.indexOf("=");
|
26
|
+
if (eq >= 0) {
|
27
|
+
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(
|
28
|
+
entry.slice(eq + 1)
|
29
|
+
);
|
30
|
+
}
|
31
|
+
});
|
28
32
|
// if variables was provided, try to format it.
|
29
33
|
if (parameters.variables) {
|
30
34
|
try {
|
31
|
-
parameters.variables =
|
32
|
-
JSON.
|
35
|
+
parameters.variables = JSON.stringify(
|
36
|
+
JSON.parse(parameters.variables),
|
37
|
+
null,
|
38
|
+
2
|
39
|
+
);
|
33
40
|
} catch (error) {
|
34
41
|
// Do nothing, we want to display the invalid JSON as a string, rather
|
35
42
|
// than present an error.
|
36
43
|
}
|
37
44
|
}
|
38
45
|
|
39
|
-
const updateURL = function() {
|
40
|
-
const newSearch = Object.keys(parameters).
|
41
|
-
|
42
|
-
|
46
|
+
const updateURL = function () {
|
47
|
+
const newSearch = Object.keys(parameters).
|
48
|
+
map(function (key) {
|
49
|
+
return `${encodeURIComponent(
|
50
|
+
key
|
51
|
+
)}=${encodeURIComponent(parameters[key])}`;
|
52
|
+
}).
|
53
|
+
join("&");
|
43
54
|
|
44
55
|
history.replaceState(null, null, `?${newSearch}`);
|
45
|
-
}
|
56
|
+
};
|
46
57
|
|
47
58
|
// When the query and variables string is edited, update the URL bar so
|
48
59
|
// that it can be easily shared
|
49
|
-
const onEditQuery = function(newQuery) {
|
60
|
+
const onEditQuery = function (newQuery) {
|
50
61
|
parameters.query = newQuery;
|
51
62
|
updateURL();
|
52
|
-
}
|
63
|
+
};
|
53
64
|
|
54
|
-
const onEditVariables = function(newVariables) {
|
65
|
+
const onEditVariables = function (newVariables) {
|
55
66
|
parameters.variables = newVariables;
|
56
67
|
updateURL();
|
57
|
-
}
|
68
|
+
};
|
58
69
|
|
59
70
|
// Defines a GraphQL fetcher using the fetch API.
|
60
|
-
const graphQLFetcher = function(graphQLParams) {
|
71
|
+
const graphQLFetcher = function (graphQLParams) {
|
61
72
|
const graphQLEndpoint = window.Decidim.config.get("graphql_endpoint");
|
62
73
|
return fetch(graphQLEndpoint, {
|
63
74
|
method: "post",
|
64
75
|
headers: JSON.parse(window.Decidim.config.get("request_headers")),
|
65
76
|
body: JSON.stringify(graphQLParams),
|
66
77
|
credentials: "include"
|
67
|
-
}).then(function(response) {
|
78
|
+
}).then(function (response) {
|
68
79
|
try {
|
69
80
|
return response.json();
|
70
81
|
} catch (error) {
|
71
82
|
return {
|
72
|
-
|
73
|
-
|
74
|
-
|
83
|
+
status: response.status,
|
84
|
+
message:
|
85
|
+
"The server responded with invalid JSON, this is probably a server-side error",
|
86
|
+
response: response.text()
|
75
87
|
};
|
76
88
|
}
|
77
|
-
})
|
78
|
-
}
|
89
|
+
});
|
90
|
+
};
|
79
91
|
|
80
92
|
window.addEventListener("DOMContentLoaded", () => {
|
81
|
-
|
82
|
-
|
93
|
+
const container = document.getElementById("graphiql-container");
|
94
|
+
|
95
|
+
const root = createRoot(container);
|
96
|
+
|
97
|
+
root.render(
|
83
98
|
React.createElement(GraphiQL, {
|
84
99
|
fetcher: graphQLFetcher,
|
85
100
|
defaultQuery: window.Decidim.config.get("default_query"),
|
@@ -87,7 +102,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
|
87
102
|
variables: parameters.variables,
|
88
103
|
onEditQuery: onEditQuery,
|
89
104
|
onEditVariables: onEditVariables
|
90
|
-
})
|
91
|
-
|
92
|
-
)
|
105
|
+
})
|
106
|
+
);
|
93
107
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="content">
|
2
2
|
<div class="version">Decidim <%= Decidim.version %></div>
|
3
3
|
|
4
|
-
<h1><%=
|
4
|
+
<h1><%= current_organization_name %> API documentation</h1>
|
5
5
|
<% if defined?(graphiql_path) %>
|
6
6
|
<%= link_to "Explore the API interactively with GraphiQL", graphiql_path %>
|
7
7
|
<% end %>
|
data/config/routes.rb
CHANGED
data/decidim-api.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.version = Decidim::Api.version
|
11
11
|
s.authors = ["Josep Jaume Rey Peroy", "Marc Riera Casals", "Oriol Gual Oliva"]
|
12
12
|
s.email = ["josepjaume@gmail.com", "mrc2407@gmail.com", "oriolgual@gmail.com"]
|
13
|
-
s.license = "AGPL-3.0
|
13
|
+
s.license = "AGPL-3.0"
|
14
14
|
s.homepage = "https://decidim.org"
|
15
15
|
s.metadata = {
|
16
16
|
"bug_tracker_uri" => "https://github.com/decidim/decidim/issues",
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
"homepage_uri" => "https://decidim.org",
|
20
20
|
"source_code_uri" => "https://github.com/decidim/decidim"
|
21
21
|
}
|
22
|
-
s.required_ruby_version = "~> 3.
|
22
|
+
s.required_ruby_version = "~> 3.2.0"
|
23
23
|
|
24
24
|
s.name = "decidim-api"
|
25
25
|
s.summary = "Decidim API module"
|
@@ -32,14 +32,11 @@ Gem::Specification.new do |s|
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
s.add_dependency "commonmarker", "~> 0.23.0", ">= 0.23.9"
|
36
35
|
s.add_dependency "decidim-core", Decidim::Api.version
|
37
|
-
|
38
|
-
s.add_dependency "graphql", "~>
|
39
|
-
s.add_dependency "graphql-docs", "~> 3.0.1"
|
36
|
+
s.add_dependency "graphql", "~> 2.2.6"
|
37
|
+
s.add_dependency "graphql-docs", "~> 4.0"
|
40
38
|
s.add_dependency "rack-cors", "~> 1.0"
|
41
39
|
|
42
|
-
s.add_development_dependency "decidim-assemblies", Decidim::Api.version
|
43
40
|
s.add_development_dependency "decidim-comments", Decidim::Api.version
|
44
41
|
s.add_development_dependency "decidim-dev", Decidim::Api.version
|
45
42
|
s.add_development_dependency "decidim-participatory_processes", Decidim::Api.version
|
@@ -7,7 +7,7 @@ module Decidim
|
|
7
7
|
# @example Adding a header to the request
|
8
8
|
# config.headers["My-Header"] = -> (view_context) { "My-Value" }
|
9
9
|
#
|
10
|
-
# @return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are `->(view_context) { ... }` procs to
|
10
|
+
# @return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are `->(view_context) { ... }` procs to determine values
|
11
11
|
attr_accessor :headers
|
12
12
|
|
13
13
|
attr_accessor :query_params, :initial_query, :csrf, :title, :logo
|
@@ -41,438 +41,3 @@ shared_context "with a graphql decidim component" do
|
|
41
41
|
)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
shared_examples "with resource visibility" do
|
46
|
-
let(:process_space_factory) { :participatory_process }
|
47
|
-
let(:space_type) { "participatoryProcess" }
|
48
|
-
|
49
|
-
shared_examples "graphQL visible resource" do
|
50
|
-
it "is visible" do
|
51
|
-
expect(response[space_type]["components"].first[lookout_key]).to eq(query_result)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
shared_examples "graphQL hidden space" do
|
56
|
-
it "should not be visible" do
|
57
|
-
expect(response[space_type]).to be_nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
shared_examples "graphQL hidden component" do
|
62
|
-
it "should not be visible" do
|
63
|
-
expect(response[space_type]["components"].first).to be_nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
shared_examples "graphQL resource visible for admin" do
|
68
|
-
context "when the user is admin" do
|
69
|
-
let!(:current_user) { create(:user, :admin, :confirmed, organization: current_organization) }
|
70
|
-
|
71
|
-
it_behaves_like "graphQL visible resource"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
shared_examples "graphQL space hidden to visitor" do
|
76
|
-
context "when user is visitor" do
|
77
|
-
let!(:current_user) { nil }
|
78
|
-
it_behaves_like "graphQL hidden space"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when space is published" do
|
83
|
-
let!(:participatory_process) { create(process_space_factory, :published, :with_steps, organization: current_organization) }
|
84
|
-
|
85
|
-
context "when component is published" do
|
86
|
-
let!(:current_component) { create(component_factory, :published, participatory_space: participatory_process) }
|
87
|
-
|
88
|
-
it_behaves_like "graphQL resource visible for admin"
|
89
|
-
|
90
|
-
context "when the user is space admin" do
|
91
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
92
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
93
|
-
it_behaves_like "graphQL visible resource"
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when the user is space collaborator" do
|
97
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
98
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
99
|
-
it_behaves_like "graphQL visible resource"
|
100
|
-
end
|
101
|
-
|
102
|
-
context "when the user is space moderator" do
|
103
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
104
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
105
|
-
it_behaves_like "graphQL visible resource"
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when the user is space valuator" do
|
109
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
110
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
111
|
-
it_behaves_like "graphQL visible resource"
|
112
|
-
end
|
113
|
-
|
114
|
-
context "when user is visitor" do
|
115
|
-
let!(:current_user) { nil }
|
116
|
-
it_behaves_like "graphQL visible resource"
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when user is member" do
|
120
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
121
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
122
|
-
it_behaves_like "graphQL visible resource"
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when user is member" do
|
126
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
127
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
128
|
-
it_behaves_like "graphQL visible resource"
|
129
|
-
end
|
130
|
-
|
131
|
-
context "when user is normal user" do
|
132
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
133
|
-
it_behaves_like "graphQL visible resource"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when component is not published" do
|
138
|
-
let!(:current_component) { create(component_factory, :unpublished, participatory_space: participatory_process) }
|
139
|
-
|
140
|
-
it_behaves_like "graphQL resource visible for admin"
|
141
|
-
|
142
|
-
context "when the user is space admin" do
|
143
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
144
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
145
|
-
it_behaves_like "graphQL visible resource"
|
146
|
-
end
|
147
|
-
|
148
|
-
context "when the user is space collaborator" do
|
149
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
150
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
151
|
-
it_behaves_like "graphQL hidden component"
|
152
|
-
end
|
153
|
-
|
154
|
-
context "when the user is space moderator" do
|
155
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
156
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
157
|
-
it_behaves_like "graphQL hidden component"
|
158
|
-
end
|
159
|
-
|
160
|
-
context "when the user is space valuator" do
|
161
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
162
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
163
|
-
it_behaves_like "graphQL visible resource"
|
164
|
-
end
|
165
|
-
|
166
|
-
context "when user is visitor" do
|
167
|
-
let!(:current_user) { nil }
|
168
|
-
|
169
|
-
it_behaves_like "graphQL hidden component"
|
170
|
-
end
|
171
|
-
|
172
|
-
context "when user is normal user" do
|
173
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
174
|
-
it_behaves_like "graphQL hidden component"
|
175
|
-
end
|
176
|
-
|
177
|
-
context "when user is member" do
|
178
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
179
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
180
|
-
it_behaves_like "graphQL hidden component"
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "when space is published, private and transparent" do
|
186
|
-
let(:process_space_factory) { :assembly }
|
187
|
-
let(:space_type) { "assembly" }
|
188
|
-
|
189
|
-
let(:participatory_process_query) do
|
190
|
-
%(
|
191
|
-
assembly(id: #{participatory_process.id}) {
|
192
|
-
components(filter: {type: "#{component_type}"}){
|
193
|
-
id
|
194
|
-
name {
|
195
|
-
translation(locale: "#{locale}")
|
196
|
-
}
|
197
|
-
weight
|
198
|
-
__typename
|
199
|
-
...fooComponent
|
200
|
-
}
|
201
|
-
id
|
202
|
-
}
|
203
|
-
)
|
204
|
-
end
|
205
|
-
let!(:participatory_process) { create(process_space_factory, :published, :private, :transparent, organization: current_organization) }
|
206
|
-
|
207
|
-
context "when component is published" do
|
208
|
-
let!(:current_component) { create(component_factory, :published, participatory_space: participatory_process) }
|
209
|
-
|
210
|
-
it_behaves_like "graphQL resource visible for admin"
|
211
|
-
|
212
|
-
context "when the user is space admin" do
|
213
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
214
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "admin") }
|
215
|
-
it_behaves_like "graphQL visible resource"
|
216
|
-
end
|
217
|
-
|
218
|
-
context "when the user is space collaborator" do
|
219
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
220
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "collaborator") }
|
221
|
-
it_behaves_like "graphQL visible resource"
|
222
|
-
end
|
223
|
-
|
224
|
-
context "when the user is space moderator" do
|
225
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
226
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "moderator") }
|
227
|
-
it_behaves_like "graphQL visible resource"
|
228
|
-
end
|
229
|
-
|
230
|
-
context "when the user is space valuator" do
|
231
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
232
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "valuator") }
|
233
|
-
it_behaves_like "graphQL visible resource"
|
234
|
-
end
|
235
|
-
|
236
|
-
context "when user is visitor" do
|
237
|
-
let!(:current_user) { nil }
|
238
|
-
it_behaves_like "graphQL visible resource"
|
239
|
-
end
|
240
|
-
|
241
|
-
context "when user is member" do
|
242
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
243
|
-
let!(:participatory_space_private_user) { create(:assembly_private_user, user: current_user, privatable_to: participatory_process) }
|
244
|
-
it_behaves_like "graphQL visible resource"
|
245
|
-
end
|
246
|
-
|
247
|
-
context "when user is normal user" do
|
248
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
249
|
-
it_behaves_like "graphQL visible resource"
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context "when component is not published" do
|
254
|
-
let!(:current_component) { create(component_factory, :unpublished, participatory_space: participatory_process) }
|
255
|
-
|
256
|
-
it_behaves_like "graphQL resource visible for admin"
|
257
|
-
|
258
|
-
context "when the user is space admin" do
|
259
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
260
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "admin") }
|
261
|
-
it_behaves_like "graphQL visible resource"
|
262
|
-
end
|
263
|
-
|
264
|
-
context "when the user is space collaborator" do
|
265
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
266
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "collaborator") }
|
267
|
-
it_behaves_like "graphQL visible resource"
|
268
|
-
end
|
269
|
-
|
270
|
-
context "when the user is space moderator" do
|
271
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
272
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "moderator") }
|
273
|
-
it_behaves_like "graphQL hidden component"
|
274
|
-
end
|
275
|
-
|
276
|
-
context "when the user is space valuator" do
|
277
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
278
|
-
let!(:role) { create(:assembly_user_role, assembly: participatory_process, user: current_user, role: "valuator") }
|
279
|
-
it_behaves_like "graphQL visible resource"
|
280
|
-
end
|
281
|
-
|
282
|
-
context "when user is visitor" do
|
283
|
-
let!(:current_user) { nil }
|
284
|
-
it_behaves_like "graphQL hidden component"
|
285
|
-
end
|
286
|
-
|
287
|
-
context "when user is normal user" do
|
288
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
289
|
-
it_behaves_like "graphQL hidden component"
|
290
|
-
end
|
291
|
-
|
292
|
-
context "when user is member" do
|
293
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
294
|
-
let!(:participatory_space_private_user) { create(:assembly_private_user, user: current_user, privatable_to: participatory_process) }
|
295
|
-
it_behaves_like "graphQL hidden component"
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
context "when space is published but private" do
|
301
|
-
let!(:participatory_process) { create(process_space_factory, :published, :private, :with_steps, organization: current_organization) }
|
302
|
-
|
303
|
-
context "when component is published" do
|
304
|
-
let!(:current_component) { create(component_factory, :published, participatory_space: participatory_process) }
|
305
|
-
|
306
|
-
it_behaves_like "graphQL resource visible for admin"
|
307
|
-
|
308
|
-
context "when the user is space admin" do
|
309
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
310
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
311
|
-
it_behaves_like "graphQL hidden space"
|
312
|
-
end
|
313
|
-
|
314
|
-
context "when the user is space collaborator" do
|
315
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
316
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
317
|
-
it_behaves_like "graphQL hidden space"
|
318
|
-
end
|
319
|
-
|
320
|
-
context "when the user is space moderator" do
|
321
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
322
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
323
|
-
|
324
|
-
it_behaves_like "graphQL hidden space"
|
325
|
-
end
|
326
|
-
|
327
|
-
context "when the user is space valuator" do
|
328
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
329
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
330
|
-
it_behaves_like "graphQL hidden space"
|
331
|
-
end
|
332
|
-
|
333
|
-
it_behaves_like "graphQL space hidden to visitor"
|
334
|
-
|
335
|
-
context "when user is normal user" do
|
336
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
337
|
-
it_behaves_like "graphQL hidden space"
|
338
|
-
end
|
339
|
-
|
340
|
-
context "when user is member" do
|
341
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
342
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
343
|
-
it_behaves_like "graphQL visible resource"
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
context "when component is not published" do
|
348
|
-
let!(:current_component) { create(component_factory, :unpublished, participatory_space: participatory_process) }
|
349
|
-
|
350
|
-
it_behaves_like "graphQL resource visible for admin"
|
351
|
-
|
352
|
-
context "when the user is space admin" do
|
353
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
354
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
355
|
-
it_behaves_like "graphQL hidden space"
|
356
|
-
end
|
357
|
-
|
358
|
-
context "when the user is space collaborator" do
|
359
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
360
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
361
|
-
it_behaves_like "graphQL hidden space"
|
362
|
-
end
|
363
|
-
|
364
|
-
context "when the user is space moderator" do
|
365
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
366
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
367
|
-
it_behaves_like "graphQL hidden space"
|
368
|
-
end
|
369
|
-
|
370
|
-
context "when the user is space valuator" do
|
371
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
372
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
373
|
-
it_behaves_like "graphQL hidden space"
|
374
|
-
end
|
375
|
-
it_behaves_like "graphQL space hidden to visitor"
|
376
|
-
|
377
|
-
context "when user is member" do
|
378
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
379
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
380
|
-
it_behaves_like "graphQL hidden component"
|
381
|
-
end
|
382
|
-
context "when user is normal user" do
|
383
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
384
|
-
it_behaves_like "graphQL hidden space"
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
context "when space is unpublished" do
|
390
|
-
let(:participatory_process) { create(process_space_factory, :unpublished, :with_steps, organization: current_organization) }
|
391
|
-
|
392
|
-
context "when component is published" do
|
393
|
-
let!(:current_component) { create(component_factory, :published, participatory_space: participatory_process) }
|
394
|
-
|
395
|
-
it_behaves_like "graphQL resource visible for admin"
|
396
|
-
|
397
|
-
context "when the user is space admin" do
|
398
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
399
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
400
|
-
it_behaves_like "graphQL hidden space"
|
401
|
-
end
|
402
|
-
|
403
|
-
context "when the user is space collaborator" do
|
404
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
405
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
406
|
-
it_behaves_like "graphQL hidden space"
|
407
|
-
end
|
408
|
-
|
409
|
-
context "when the user is space moderator" do
|
410
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
411
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
412
|
-
it_behaves_like "graphQL hidden space"
|
413
|
-
end
|
414
|
-
|
415
|
-
context "when the user is space valuator" do
|
416
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
417
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
418
|
-
it_behaves_like "graphQL hidden space"
|
419
|
-
end
|
420
|
-
|
421
|
-
it_behaves_like "graphQL space hidden to visitor"
|
422
|
-
|
423
|
-
context "when user is member" do
|
424
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
425
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
426
|
-
it_behaves_like "graphQL hidden space"
|
427
|
-
end
|
428
|
-
|
429
|
-
context "when user is normal user" do
|
430
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
431
|
-
it_behaves_like "graphQL hidden space"
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
context "when component is not published" do
|
436
|
-
let!(:current_component) { create(component_factory, :unpublished, participatory_space: participatory_process) }
|
437
|
-
|
438
|
-
it_behaves_like "graphQL resource visible for admin"
|
439
|
-
|
440
|
-
context "when the user is space admin" do
|
441
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
442
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "admin") }
|
443
|
-
it_behaves_like "graphQL hidden space"
|
444
|
-
end
|
445
|
-
|
446
|
-
context "when the user is space collaborator" do
|
447
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
448
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "collaborator") }
|
449
|
-
it_behaves_like "graphQL hidden space"
|
450
|
-
end
|
451
|
-
|
452
|
-
context "when the user is space moderator" do
|
453
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
454
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "moderator") }
|
455
|
-
it_behaves_like "graphQL hidden space"
|
456
|
-
end
|
457
|
-
|
458
|
-
context "when the user is space valuator" do
|
459
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
460
|
-
let!(:role) { create(:participatory_process_user_role, participatory_process:, user: current_user, role: "valuator") }
|
461
|
-
it_behaves_like "graphQL hidden space"
|
462
|
-
end
|
463
|
-
it_behaves_like "graphQL space hidden to visitor"
|
464
|
-
|
465
|
-
context "when user is member" do
|
466
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
467
|
-
let!(:participatory_space_private_user) { create(:participatory_space_private_user, user: current_user, privatable_to: participatory_process) }
|
468
|
-
it_behaves_like "graphQL hidden space"
|
469
|
-
end
|
470
|
-
|
471
|
-
context "when user is normal user" do
|
472
|
-
let!(:current_user) { create(:user, :confirmed, organization: current_organization) }
|
473
|
-
|
474
|
-
it_behaves_like "graphQL hidden space"
|
475
|
-
end
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
@@ -16,13 +16,12 @@ shared_examples "implements stats type" do
|
|
16
16
|
{ "name" => "results_count", "value" => 0 },
|
17
17
|
{ "name" => "debates_count", "value" => 0 },
|
18
18
|
{ "name" => "sortitions_count", "value" => 0 },
|
19
|
-
{ "name" => "posts_count", "value" => 0 }
|
20
|
-
{ "name" => "elections_count", "value" => 0 }
|
19
|
+
{ "name" => "posts_count", "value" => 0 }
|
21
20
|
]
|
22
21
|
}
|
23
22
|
end
|
24
23
|
|
25
|
-
it "executes
|
24
|
+
it "executes successfully" do
|
26
25
|
expect { response }.not_to raise_error
|
27
26
|
end
|
28
27
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
shared_context "with a graphql class type" do
|
4
4
|
let!(:current_organization) { create(:organization) }
|
5
|
-
let!(:current_user) { create(:user,
|
5
|
+
let!(:current_user) { create(:user, organization: current_organization) }
|
6
6
|
let!(:current_component) { create(:component) }
|
7
7
|
let(:model) { OpenStruct.new({}) }
|
8
8
|
let(:type_class) { described_class }
|
@@ -27,7 +27,8 @@ shared_context "with a graphql class type" do
|
|
27
27
|
root_value:,
|
28
28
|
context: {
|
29
29
|
current_organization:,
|
30
|
-
current_user
|
30
|
+
current_user:,
|
31
|
+
current_component:
|
31
32
|
},
|
32
33
|
variables:
|
33
34
|
)
|
@@ -5,76 +5,6 @@ module Decidim
|
|
5
5
|
module Types
|
6
6
|
class BaseObject < GraphQL::Schema::Object
|
7
7
|
field_class Types::BaseField
|
8
|
-
|
9
|
-
def self.authorized?(object, context)
|
10
|
-
chain = []
|
11
|
-
|
12
|
-
subject = determine_subject_name(object)
|
13
|
-
context[subject] = object
|
14
|
-
|
15
|
-
chain.unshift(allowed_to?(:read, :participatory_space, object, context)) if object.respond_to?(:participatory_space)
|
16
|
-
chain.unshift(allowed_to?(:read, :component, object, context)) if object.respond_to?(:component) && object.component.present?
|
17
|
-
|
18
|
-
super && chain.all?
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.determine_subject_name(object)
|
22
|
-
object.class.name.split("::").last.underscore.to_sym
|
23
|
-
end
|
24
|
-
|
25
|
-
# This is a simplified adaptation of allowed_to? from NeedsPermission concern
|
26
|
-
# @param action [Symbol] The action performed. Most cases the action is :read
|
27
|
-
# @param subject [Object] The name of the subject. Ex: :participatory_space, :component, or object
|
28
|
-
# @param object [ActiveModel::Base] The object that is being represented.
|
29
|
-
# @param context [GraphQL::Query::Context] The GraphQL context
|
30
|
-
#
|
31
|
-
# @return Boolean
|
32
|
-
def self.allowed_to?(action, subject, object, context)
|
33
|
-
unless subject.is_a?(::Symbol)
|
34
|
-
subject = determine_subject_name(object)
|
35
|
-
context[subject] = object
|
36
|
-
end
|
37
|
-
|
38
|
-
permission_action = Decidim::PermissionAction.new(scope: :public, action:, subject:)
|
39
|
-
|
40
|
-
permission_chain(object).inject(permission_action) do |current_permission_action, permission_class|
|
41
|
-
permission_class.new(
|
42
|
-
context[:current_user],
|
43
|
-
current_permission_action,
|
44
|
-
local_context(object, context)
|
45
|
-
).permissions
|
46
|
-
end.allowed?
|
47
|
-
end
|
48
|
-
|
49
|
-
# Injects into context object current_participatory_space and current_component keys as they are needed
|
50
|
-
#
|
51
|
-
# @param object [ActiveModel::Base] The object that is being represented.
|
52
|
-
# @param context [GraphQL::Query::Context] The GraphQL context
|
53
|
-
#
|
54
|
-
# @return Hash
|
55
|
-
def self.local_context(object, context)
|
56
|
-
context[:current_participatory_space] = object.participatory_space if object.respond_to?(:participatory_space)
|
57
|
-
context[:current_component] = object.component if object.respond_to?(:component) && object.component.present?
|
58
|
-
|
59
|
-
context.to_h
|
60
|
-
end
|
61
|
-
|
62
|
-
# Creates the permission chain arrau that contains all the permission classes required to authorize a certain resource
|
63
|
-
# We are using unshift as we need the Admin and base permissions to be last in the chain
|
64
|
-
# @param object [ActiveModel::Base] The object that is being represented.
|
65
|
-
#
|
66
|
-
# @return [Decidim::DefaultPermissions]
|
67
|
-
def self.permission_chain(object)
|
68
|
-
permissions = [
|
69
|
-
Decidim::Admin::Permissions,
|
70
|
-
Decidim::Permissions
|
71
|
-
]
|
72
|
-
|
73
|
-
permissions.unshift(object.participatory_space.manifest.permissions_class) if object.respond_to?(:participatory_space)
|
74
|
-
permissions.unshift(object.component.manifest.permissions_class) if object.respond_to?(:component) && object.component.present?
|
75
|
-
|
76
|
-
permissions
|
77
|
-
end
|
78
8
|
end
|
79
9
|
end
|
80
10
|
end
|
data/lib/decidim/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.29.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep Jaume Rey Peroy
|
@@ -10,70 +10,50 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: commonmarker
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.23.0
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.23.9
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
requirements:
|
29
|
-
- - "~>"
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: 0.23.0
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.23.9
|
35
15
|
- !ruby/object:Gem::Dependency
|
36
16
|
name: decidim-core
|
37
17
|
requirement: !ruby/object:Gem::Requirement
|
38
18
|
requirements:
|
39
19
|
- - '='
|
40
20
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
21
|
+
version: 0.29.0.rc1
|
42
22
|
type: :runtime
|
43
23
|
prerelease: false
|
44
24
|
version_requirements: !ruby/object:Gem::Requirement
|
45
25
|
requirements:
|
46
26
|
- - '='
|
47
27
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
28
|
+
version: 0.29.0.rc1
|
49
29
|
- !ruby/object:Gem::Dependency
|
50
30
|
name: graphql
|
51
31
|
requirement: !ruby/object:Gem::Requirement
|
52
32
|
requirements:
|
53
33
|
- - "~>"
|
54
34
|
- !ruby/object:Gem::Version
|
55
|
-
version: 2.
|
35
|
+
version: 2.2.6
|
56
36
|
type: :runtime
|
57
37
|
prerelease: false
|
58
38
|
version_requirements: !ruby/object:Gem::Requirement
|
59
39
|
requirements:
|
60
40
|
- - "~>"
|
61
41
|
- !ruby/object:Gem::Version
|
62
|
-
version: 2.
|
42
|
+
version: 2.2.6
|
63
43
|
- !ruby/object:Gem::Dependency
|
64
44
|
name: graphql-docs
|
65
45
|
requirement: !ruby/object:Gem::Requirement
|
66
46
|
requirements:
|
67
47
|
- - "~>"
|
68
48
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
49
|
+
version: '4.0'
|
70
50
|
type: :runtime
|
71
51
|
prerelease: false
|
72
52
|
version_requirements: !ruby/object:Gem::Requirement
|
73
53
|
requirements:
|
74
54
|
- - "~>"
|
75
55
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
56
|
+
version: '4.0'
|
77
57
|
- !ruby/object:Gem::Dependency
|
78
58
|
name: rack-cors
|
79
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,62 +68,48 @@ dependencies:
|
|
88
68
|
- - "~>"
|
89
69
|
- !ruby/object:Gem::Version
|
90
70
|
version: '1.0'
|
91
|
-
- !ruby/object:Gem::Dependency
|
92
|
-
name: decidim-assemblies
|
93
|
-
requirement: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - '='
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 0.28.5
|
98
|
-
type: :development
|
99
|
-
prerelease: false
|
100
|
-
version_requirements: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - '='
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: 0.28.5
|
105
71
|
- !ruby/object:Gem::Dependency
|
106
72
|
name: decidim-comments
|
107
73
|
requirement: !ruby/object:Gem::Requirement
|
108
74
|
requirements:
|
109
75
|
- - '='
|
110
76
|
- !ruby/object:Gem::Version
|
111
|
-
version: 0.
|
77
|
+
version: 0.29.0.rc1
|
112
78
|
type: :development
|
113
79
|
prerelease: false
|
114
80
|
version_requirements: !ruby/object:Gem::Requirement
|
115
81
|
requirements:
|
116
82
|
- - '='
|
117
83
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.
|
84
|
+
version: 0.29.0.rc1
|
119
85
|
- !ruby/object:Gem::Dependency
|
120
86
|
name: decidim-dev
|
121
87
|
requirement: !ruby/object:Gem::Requirement
|
122
88
|
requirements:
|
123
89
|
- - '='
|
124
90
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.
|
91
|
+
version: 0.29.0.rc1
|
126
92
|
type: :development
|
127
93
|
prerelease: false
|
128
94
|
version_requirements: !ruby/object:Gem::Requirement
|
129
95
|
requirements:
|
130
96
|
- - '='
|
131
97
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.
|
98
|
+
version: 0.29.0.rc1
|
133
99
|
- !ruby/object:Gem::Dependency
|
134
100
|
name: decidim-participatory_processes
|
135
101
|
requirement: !ruby/object:Gem::Requirement
|
136
102
|
requirements:
|
137
103
|
- - '='
|
138
104
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.
|
105
|
+
version: 0.29.0.rc1
|
140
106
|
type: :development
|
141
107
|
prerelease: false
|
142
108
|
version_requirements: !ruby/object:Gem::Requirement
|
143
109
|
requirements:
|
144
110
|
- - '='
|
145
111
|
- !ruby/object:Gem::Version
|
146
|
-
version: 0.
|
112
|
+
version: 0.29.0.rc1
|
147
113
|
description: API engine for decidim
|
148
114
|
email:
|
149
115
|
- josepjaume@gmail.com
|
@@ -196,7 +162,7 @@ files:
|
|
196
162
|
- lib/tasks/decidim_api_docs.rake
|
197
163
|
homepage: https://decidim.org
|
198
164
|
licenses:
|
199
|
-
- AGPL-3.0
|
165
|
+
- AGPL-3.0
|
200
166
|
metadata:
|
201
167
|
bug_tracker_uri: https://github.com/decidim/decidim/issues
|
202
168
|
documentation_uri: https://docs.decidim.org/
|
@@ -211,14 +177,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
177
|
requirements:
|
212
178
|
- - "~>"
|
213
179
|
- !ruby/object:Gem::Version
|
214
|
-
version: 3.
|
180
|
+
version: 3.2.0
|
215
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
182
|
requirements:
|
217
|
-
- - "
|
183
|
+
- - ">"
|
218
184
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
185
|
+
version: 1.3.1
|
220
186
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.4.10
|
222
188
|
signing_key:
|
223
189
|
specification_version: 4
|
224
190
|
summary: Decidim API module
|