decidim-restfull-blogs 0.3.11
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 +7 -0
- data/app/controllers/decidim/api/rest_full/blogs/blogs_controller.rb +174 -0
- data/app/controllers/decidim/api/rest_full/components/blog_components_controller.rb +71 -0
- data/app/serializers/decidim/api/rest_full/blogs/blog_component_serializer.rb +25 -0
- data/app/serializers/decidim/api/rest_full/blogs/blog_serializer.rb +70 -0
- data/app/serializers/decidim/api/rest_full/blogs/post_serializer.rb +12 -0
- data/app/services/decidim/rest_full/blogs/blogs_operations.rb +108 -0
- data/config/locales/decidim_rest_full_blogs.en.yml +13 -0
- data/lib/decidim/rest_full/blogs/engine.rb +55 -0
- data/lib/decidim/rest_full/blogs/test_definitions.rb +6 -0
- data/lib/decidim/rest_full/test/definitions/blog.rb +112 -0
- data/lib/decidim/rest_full/test/definitions/blog_component_schema.rb +11 -0
- data/lib/decidim/rest_full/test/definitions/blogs.rb +3 -0
- data/lib/decidim/rest_full/test/definitions/tags/blog_tag.rb +26 -0
- data/lib/decidim-restfull-blogs.rb +13 -0
- data/spec/requests/decidim/api/rest_full/blogs/blogs_controller_create_spec.rb +83 -0
- data/spec/requests/decidim/api/rest_full/blogs/blogs_controller_index_spec.rb +168 -0
- data/spec/requests/decidim/api/rest_full/blogs/blogs_controller_show_pagination_spec.rb +125 -0
- data/spec/requests/decidim/api/rest_full/blogs/blogs_controller_show_spec.rb +234 -0
- data/spec/requests/decidim/api/rest_full/components/blog_components_controller_index_spec.rb +79 -0
- data/spec/requests/decidim/api/rest_full/components/blog_components_controller_show_spec.rb +54 -0
- data/spec/requests/decidim/api/rest_full/scenarios/blog_published_at_desc_prev_next_chain_spec.rb +71 -0
- metadata +99 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
RSpec.describe Decidim::Api::RestFull::Components::BlogComponentsController do
|
|
5
|
+
path "/components/blog_components" do
|
|
6
|
+
get "Blog Components" do
|
|
7
|
+
tags "Components"
|
|
8
|
+
produces "application/json"
|
|
9
|
+
operationId "listBlogComponents"
|
|
10
|
+
description "List or search blog components of the organization"
|
|
11
|
+
it_behaves_like "paginated params"
|
|
12
|
+
it_behaves_like "localized params"
|
|
13
|
+
it_behaves_like "filtered params", filter: "participatory_space_id", item_schema: { type: :string }, only: :integer
|
|
14
|
+
it_behaves_like "filtered params", filter: "participatory_space_type", item_schema: { type: :string, example: "Decidim::Assembly" }, only: :string
|
|
15
|
+
it_behaves_like "filtered params", filter: "name", item_schema: { type: :string }, only: :string
|
|
16
|
+
|
|
17
|
+
describe_api_endpoint(
|
|
18
|
+
controller: Decidim::Api::RestFull::Components::BlogComponentsController,
|
|
19
|
+
action: :index,
|
|
20
|
+
security_types: [:impersonationFlow, :credentialFlow],
|
|
21
|
+
scopes: ["public"],
|
|
22
|
+
permissions: ["public.component.read"]
|
|
23
|
+
) do
|
|
24
|
+
let(:component) { create(:component, manifest_name: "blogs") }
|
|
25
|
+
let!(:assembly) { create(:assembly, organization:) }
|
|
26
|
+
let!(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
27
|
+
let!(:organization) { create(:organization, available_locales: ["en"]) }
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
proposals = create(:component, participatory_space: participatory_process, manifest_name: "proposals", published_at: Time.zone.now)
|
|
31
|
+
create(:proposal, component: proposals)
|
|
32
|
+
create(:proposal, component: proposals)
|
|
33
|
+
|
|
34
|
+
create(
|
|
35
|
+
:component,
|
|
36
|
+
manifest_name: "blogs",
|
|
37
|
+
participatory_space: participatory_process,
|
|
38
|
+
settings: { awesome_voting_manifest: :voting_cards }
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it_behaves_like "localized endpoint"
|
|
43
|
+
|
|
44
|
+
response "200", "List of blog components" do
|
|
45
|
+
produces "application/json"
|
|
46
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:blog_component_index_response)
|
|
47
|
+
|
|
48
|
+
context "with no filter params" do
|
|
49
|
+
let(:"locales[]") { %w(en fr) }
|
|
50
|
+
let(:page) { 1 }
|
|
51
|
+
let(:per_page) { 10 }
|
|
52
|
+
|
|
53
|
+
run_test!(example_name: :ok)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "with filter[participatory_space_type_eq]=Decidim::ParticipatoryProcess and filter[participatory_space_type_id_eq]=processId filters" do
|
|
57
|
+
let(:"filter[participatory_space_id_eq]") { participatory_process.id.to_s }
|
|
58
|
+
let(:"filter[participatory_space_type_eq]") { "Decidim::ParticipatoryProcess" }
|
|
59
|
+
let(:"locales[]") { %w(en fr) }
|
|
60
|
+
let(:page) { 1 }
|
|
61
|
+
let(:per_page) { 10 }
|
|
62
|
+
|
|
63
|
+
run_test!(example_name: :components_in_Process) do |example|
|
|
64
|
+
data = JSON.parse(example.body)["data"]
|
|
65
|
+
not_in_process = data.select { |component| component["attributes"]["participatory_space_type"] != "Decidim::ParticipatoryProcess" && component["attributes"]["participatory_space_id"] != participatory_process.id.to_s }
|
|
66
|
+
expect(not_in_process).to be_empty
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it_behaves_like "paginated endpoint" do
|
|
71
|
+
let(:create_resource) { -> { create(:component, manifest_name: "blogs", participatory_space: participatory_process) } }
|
|
72
|
+
let(:each_resource) { ->(_resource, _index) {} }
|
|
73
|
+
let(:resources) { Decidim::Component.all }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
RSpec.describe Decidim::Api::RestFull::Components::BlogComponentsController do
|
|
5
|
+
path "/components/blog_components/{id}" do
|
|
6
|
+
get "Blog Component Details" do
|
|
7
|
+
tags "Components"
|
|
8
|
+
produces "application/json"
|
|
9
|
+
operationId "showBlogComponent"
|
|
10
|
+
description "Blog component details"
|
|
11
|
+
it_behaves_like "localized params"
|
|
12
|
+
|
|
13
|
+
parameter name: "id", in: :path, schema: { type: :integer }
|
|
14
|
+
parameter name: "component_id", in: :query, schema: { type: :integer, description: "Component Id" }, required: false
|
|
15
|
+
parameter name: "space_manifest", in: :query, schema: { type: :string, enum: Decidim.participatory_space_registry.manifests.map(&:name), description: "Space type" }, required: false
|
|
16
|
+
parameter name: "space_id", in: :query, schema: { type: :integer, description: "Space Id" }, required: false
|
|
17
|
+
|
|
18
|
+
describe_api_endpoint(
|
|
19
|
+
controller: Decidim::Api::RestFull::Components::BlogComponentsController,
|
|
20
|
+
action: :show,
|
|
21
|
+
security_types: [:impersonationFlow, :credentialFlow],
|
|
22
|
+
scopes: ["public"],
|
|
23
|
+
permissions: ["public.component.read"]
|
|
24
|
+
) do
|
|
25
|
+
let(:id) { component.id }
|
|
26
|
+
|
|
27
|
+
let(:component) { create(:component, manifest_name: "blogs") }
|
|
28
|
+
let!(:assembly) { create(:assembly, organization:) }
|
|
29
|
+
let!(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
30
|
+
|
|
31
|
+
before do
|
|
32
|
+
blog_component = create(:component, participatory_space: participatory_process, manifest_name: "blogs", published_at: Time.zone.now)
|
|
33
|
+
create(:post, component: blog_component)
|
|
34
|
+
create(:post, component: blog_component)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it_behaves_like "localized endpoint"
|
|
38
|
+
|
|
39
|
+
response "200", "Blog Component" do
|
|
40
|
+
produces "application/json"
|
|
41
|
+
schema "$ref" => Decidim::RestFull::Core::DefinitionRegistry.reference(:blog_component_item_response)
|
|
42
|
+
|
|
43
|
+
context "with no filter params" do
|
|
44
|
+
let(:"locales[]") { %w(en fr) }
|
|
45
|
+
let(:page) { 1 }
|
|
46
|
+
let(:per_page) { 10 }
|
|
47
|
+
|
|
48
|
+
run_test!(example_name: :ok)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/spec/requests/decidim/api/rest_full/scenarios/blog_published_at_desc_prev_next_chain_spec.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# rubocop:disable RSpec/DescribeClass -- behaviour scenario (multi-step HTTP)
|
|
6
|
+
RSpec.describe "Blog published_at DESC prev/next chain" do
|
|
7
|
+
let!(:organization) { create(:organization, available_locales: %w(en fr)) }
|
|
8
|
+
let!(:participatory_process) { create(:participatory_process, organization:) }
|
|
9
|
+
let!(:component) do
|
|
10
|
+
create(:component, participatory_space: participatory_process, manifest_name: "blogs", published_at: Time.zone.now)
|
|
11
|
+
end
|
|
12
|
+
let!(:newest) { create(:post, component:, published_at: 1.day.ago) }
|
|
13
|
+
let!(:middle) { create(:post, component:, published_at: 2.days.ago) }
|
|
14
|
+
let!(:oldest) { create(:post, component:, published_at: 3.days.ago) }
|
|
15
|
+
|
|
16
|
+
let!(:api_client) do
|
|
17
|
+
c = create(:api_client, organization:, scopes: ["blogs"])
|
|
18
|
+
c.permissions = [Decidim::RestFull::Core::Permission.new(permission: "blogs.read")]
|
|
19
|
+
c.save!
|
|
20
|
+
c
|
|
21
|
+
end
|
|
22
|
+
let!(:token) do
|
|
23
|
+
create(:oauth_access_token, scopes: "blogs", resource_owner_id: nil, application: api_client)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:api_prefix) { "/api/rest_full/v#{Decidim::RestFull.major_minor_version}" }
|
|
27
|
+
let(:auth_headers) { { "Authorization" => "Bearer #{token.token}" } }
|
|
28
|
+
let(:chain_params) do
|
|
29
|
+
{
|
|
30
|
+
component_id: component.id,
|
|
31
|
+
space_id: participatory_process.id,
|
|
32
|
+
space_manifest: "participatory_processes",
|
|
33
|
+
order: "published_at",
|
|
34
|
+
order_direction: "desc"
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
before { host!(organization.host) }
|
|
39
|
+
|
|
40
|
+
def get_blog(id)
|
|
41
|
+
get("#{api_prefix}/blogs/#{id}", params: chain_params, headers: auth_headers)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def follow_next!(data)
|
|
45
|
+
next_link = data.dig("links", "next")
|
|
46
|
+
expect(next_link).to be_present
|
|
47
|
+
get_blog(next_link.dig("meta", "resource_id"))
|
|
48
|
+
expect(response).to have_http_status(:ok)
|
|
49
|
+
response.parsed_body["data"]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "walks newest → middle → oldest with nil prev on first and nil next on last" do
|
|
53
|
+
get_blog(newest.id)
|
|
54
|
+
expect(response).to have_http_status(:ok)
|
|
55
|
+
first = response.parsed_body["data"]
|
|
56
|
+
expect(first["id"].to_i).to eq(newest.id)
|
|
57
|
+
expect(first.dig("links", "prev")).to be_nil
|
|
58
|
+
expect(first.dig("links", "next", "meta", "resource_id").to_i).to eq(middle.id)
|
|
59
|
+
|
|
60
|
+
second = follow_next!(first)
|
|
61
|
+
expect(second["id"].to_i).to eq(middle.id)
|
|
62
|
+
expect(second.dig("links", "prev", "meta", "resource_id").to_i).to eq(newest.id)
|
|
63
|
+
expect(second.dig("links", "next", "meta", "resource_id").to_i).to eq(oldest.id)
|
|
64
|
+
|
|
65
|
+
third = follow_next!(second)
|
|
66
|
+
expect(third["id"].to_i).to eq(oldest.id)
|
|
67
|
+
expect(third.dig("links", "next")).to be_nil
|
|
68
|
+
expect(third.dig("links", "prev", "meta", "resource_id").to_i).to eq(middle.id)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
# rubocop:enable RSpec/DescribeClass
|
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: decidim-restfull-blogs
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.11
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hadrien Froger
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: decidim-blogs
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.29.0
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '0.33'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.29.0
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.33'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: decidim-restfull-core
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - '='
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.3.11
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - '='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.3.11
|
|
47
|
+
description: Decidim RestFull API — blogs
|
|
48
|
+
email:
|
|
49
|
+
- hadrien@octree.ch
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- app/controllers/decidim/api/rest_full/blogs/blogs_controller.rb
|
|
55
|
+
- app/controllers/decidim/api/rest_full/components/blog_components_controller.rb
|
|
56
|
+
- app/serializers/decidim/api/rest_full/blogs/blog_component_serializer.rb
|
|
57
|
+
- app/serializers/decidim/api/rest_full/blogs/blog_serializer.rb
|
|
58
|
+
- app/serializers/decidim/api/rest_full/blogs/post_serializer.rb
|
|
59
|
+
- app/services/decidim/rest_full/blogs/blogs_operations.rb
|
|
60
|
+
- config/locales/decidim_rest_full_blogs.en.yml
|
|
61
|
+
- lib/decidim-restfull-blogs.rb
|
|
62
|
+
- lib/decidim/rest_full/blogs/engine.rb
|
|
63
|
+
- lib/decidim/rest_full/blogs/test_definitions.rb
|
|
64
|
+
- lib/decidim/rest_full/test/definitions/blog.rb
|
|
65
|
+
- lib/decidim/rest_full/test/definitions/blog_component_schema.rb
|
|
66
|
+
- lib/decidim/rest_full/test/definitions/blogs.rb
|
|
67
|
+
- lib/decidim/rest_full/test/definitions/tags/blog_tag.rb
|
|
68
|
+
- spec/requests/decidim/api/rest_full/blogs/blogs_controller_create_spec.rb
|
|
69
|
+
- spec/requests/decidim/api/rest_full/blogs/blogs_controller_index_spec.rb
|
|
70
|
+
- spec/requests/decidim/api/rest_full/blogs/blogs_controller_show_pagination_spec.rb
|
|
71
|
+
- spec/requests/decidim/api/rest_full/blogs/blogs_controller_show_spec.rb
|
|
72
|
+
- spec/requests/decidim/api/rest_full/components/blog_components_controller_index_spec.rb
|
|
73
|
+
- spec/requests/decidim/api/rest_full/components/blog_components_controller_show_spec.rb
|
|
74
|
+
- spec/requests/decidim/api/rest_full/scenarios/blog_published_at_desc_prev_next_chain_spec.rb
|
|
75
|
+
homepage: https://git.octree.ch/decidim/decidim-chatbot/decidim-module-rest_full
|
|
76
|
+
licenses:
|
|
77
|
+
- AGPL-3.0
|
|
78
|
+
metadata:
|
|
79
|
+
rubygems_mfa_required: 'true'
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.2'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubygems_version: 3.4.19
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: Decidim RestFull API — blogs
|
|
99
|
+
test_files: []
|