Skip to content

Commit

Permalink
adds antivirus module compatibility (#120)
Browse files Browse the repository at this point in the history
* add antivirus compat

* fix spec

* readmen

* fix tests

* fix more tests

* fix system test
  • Loading branch information
microstudi authored Jan 17, 2024
1 parent 175394f commit 2376bce
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 101 deletions.
178 changes: 90 additions & 88 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
PATH
remote: .
specs:
decidim-participatory_documents (0.2.1)
decidim-participatory_documents (0.2.2)
decidim-core (>= 0.27.0, < 0.28)

GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
actioncable (6.1.7.6)
actionpack (= 6.1.7.6)
activesupport (= 6.1.7.6)
Expand Down Expand Up @@ -159,53 +160,53 @@ GEM
db-query-matchers (0.10.0)
activesupport (>= 4.0, < 7)
rspec (~> 3.0)
decidim (0.27.4)
decidim-accountability (= 0.27.4)
decidim-admin (= 0.27.4)
decidim-api (= 0.27.4)
decidim-assemblies (= 0.27.4)
decidim-blogs (= 0.27.4)
decidim-budgets (= 0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-debates (= 0.27.4)
decidim-forms (= 0.27.4)
decidim-generators (= 0.27.4)
decidim-meetings (= 0.27.4)
decidim-pages (= 0.27.4)
decidim-participatory_processes (= 0.27.4)
decidim-proposals (= 0.27.4)
decidim-sortitions (= 0.27.4)
decidim-surveys (= 0.27.4)
decidim-system (= 0.27.4)
decidim-templates (= 0.27.4)
decidim-verifications (= 0.27.4)
decidim-accountability (0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-admin (0.27.4)
decidim (0.27.5)
decidim-accountability (= 0.27.5)
decidim-admin (= 0.27.5)
decidim-api (= 0.27.5)
decidim-assemblies (= 0.27.5)
decidim-blogs (= 0.27.5)
decidim-budgets (= 0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-debates (= 0.27.5)
decidim-forms (= 0.27.5)
decidim-generators (= 0.27.5)
decidim-meetings (= 0.27.5)
decidim-pages (= 0.27.5)
decidim-participatory_processes (= 0.27.5)
decidim-proposals (= 0.27.5)
decidim-sortitions (= 0.27.5)
decidim-surveys (= 0.27.5)
decidim-system (= 0.27.5)
decidim-templates (= 0.27.5)
decidim-verifications (= 0.27.5)
decidim-accountability (0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-admin (0.27.5)
active_link_to (~> 1.0)
decidim-core (= 0.27.4)
decidim-core (= 0.27.5)
devise (~> 4.7)
devise-i18n (~> 1.2)
devise_invitable (~> 2.0)
decidim-api (0.27.4)
devise_invitable (~> 2.0, >= 2.0.9)
decidim-api (0.27.5)
graphql (~> 1.12, < 1.13)
graphql-docs (~> 2.1.0)
rack-cors (~> 1.0)
decidim-assemblies (0.27.4)
decidim-core (= 0.27.4)
decidim-blogs (0.27.4)
decidim-admin (= 0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-budgets (0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-comments (0.27.4)
decidim-core (= 0.27.4)
decidim-assemblies (0.27.5)
decidim-core (= 0.27.5)
decidim-blogs (0.27.5)
decidim-admin (= 0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-budgets (0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-comments (0.27.5)
decidim-core (= 0.27.5)
redcarpet (~> 3.5, >= 3.5.1)
decidim-core (0.27.4)
decidim-core (0.27.5)
active_link_to (~> 1.0)
acts_as_list (~> 0.9)
batch-loader (~> 1.2)
Expand All @@ -215,7 +216,7 @@ GEM
cells-rails (~> 0.1.3)
charlock_holmes (~> 0.7)
date_validator (~> 0.12.0)
decidim-api (= 0.27.4)
decidim-api (= 0.27.5)
devise (~> 4.7)
devise-i18n (~> 1.2)
diffy (~> 3.3)
Expand Down Expand Up @@ -256,15 +257,15 @@ GEM
webpacker (= 6.0.0.rc.5)
webpush (~> 1.1)
wisper (~> 2.0)
decidim-debates (0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-dev (0.27.4)
decidim-debates (0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-dev (0.27.5)
axe-core-rspec (~> 4.1.0)
byebug (~> 11.0)
capybara (~> 3.24)
db-query-matchers (~> 0.10.0)
decidim (= 0.27.4)
decidim (= 0.27.5)
erb_lint (~> 0.0.35)
factory_bot_rails (~> 4.8)
i18n-tasks (~> 0.9.18)
Expand All @@ -287,45 +288,45 @@ GEM
w3c_rspec_validators (~> 0.3.0)
webmock (~> 3.6)
wisper-rspec (~> 1.0)
decidim-forms (0.27.4)
decidim-core (= 0.27.4)
decidim-forms (0.27.5)
decidim-core (= 0.27.5)
wicked_pdf (~> 2.1)
wkhtmltopdf-binary (~> 0.12)
decidim-generators (0.27.4)
decidim-core (= 0.27.4)
decidim-meetings (0.27.4)
decidim-core (= 0.27.4)
decidim-forms (= 0.27.4)
decidim-generators (0.27.5)
decidim-core (= 0.27.5)
decidim-meetings (0.27.5)
decidim-core (= 0.27.5)
decidim-forms (= 0.27.5)
icalendar (~> 2.5)
decidim-pages (0.27.4)
decidim-core (= 0.27.4)
decidim-participatory_processes (0.27.4)
decidim-core (= 0.27.4)
decidim-proposals (0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-pages (0.27.5)
decidim-core (= 0.27.5)
decidim-participatory_processes (0.27.5)
decidim-core (= 0.27.5)
decidim-proposals (0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
doc2text (~> 0.4.5)
redcarpet (~> 3.5, >= 3.5.1)
decidim-sortitions (0.27.4)
decidim-admin (= 0.27.4)
decidim-comments (= 0.27.4)
decidim-core (= 0.27.4)
decidim-proposals (= 0.27.4)
decidim-surveys (0.27.4)
decidim-core (= 0.27.4)
decidim-forms (= 0.27.4)
decidim-templates (= 0.27.4)
decidim-system (0.27.4)
decidim-sortitions (0.27.5)
decidim-admin (= 0.27.5)
decidim-comments (= 0.27.5)
decidim-core (= 0.27.5)
decidim-proposals (= 0.27.5)
decidim-surveys (0.27.5)
decidim-core (= 0.27.5)
decidim-forms (= 0.27.5)
decidim-templates (= 0.27.5)
decidim-system (0.27.5)
active_link_to (~> 1.0)
decidim-core (= 0.27.4)
decidim-core (= 0.27.5)
devise (~> 4.7)
devise-i18n (~> 1.2)
devise_invitable (~> 2.0)
decidim-templates (0.27.4)
decidim-core (= 0.27.4)
decidim-forms (= 0.27.4)
decidim-verifications (0.27.4)
decidim-core (= 0.27.4)
devise_invitable (~> 2.0, >= 2.0.9)
decidim-templates (0.27.5)
decidim-core (= 0.27.5)
decidim-forms (= 0.27.5)
decidim-verifications (0.27.5)
decidim-core (= 0.27.5)
declarative-builder (0.1.0)
declarative-option (< 0.2.0)
declarative-option (0.1.0)
Expand All @@ -339,7 +340,7 @@ GEM
warden (~> 1.2.3)
devise-i18n (1.12.0)
devise (>= 4.9.0)
devise_invitable (2.0.8)
devise_invitable (2.0.9)
actionmailer (>= 5.0)
devise (>= 4.6)
diff-lcs (1.5.0)
Expand Down Expand Up @@ -412,7 +413,8 @@ GEM
sass (~> 3.4)
hashdiff (1.0.1)
hashie (5.0.0)
highline (2.1.0)
highline (3.0.0)
abbrev
hkdf (0.3.0)
html-pipeline (2.14.3)
activesupport (>= 2)
Expand All @@ -431,7 +433,7 @@ GEM
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
icalendar (2.9.0)
icalendar (2.10.1)
ice_cube (~> 0.16)
ice_cube (0.16.4)
ice_nine (0.11.2)
Expand All @@ -440,7 +442,7 @@ GEM
ruby-vips (>= 2.0.17, < 3)
invisible_captcha (0.13.0)
rails (>= 3.2.0)
json (2.6.3)
json (2.7.1)
jwt (2.7.1)
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -571,7 +573,7 @@ GEM
net-smtp
premailer (~> 1.7, >= 1.7.9)
public_suffix (5.0.3)
puma (5.6.7)
puma (5.6.8)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.8)
Expand Down Expand Up @@ -641,9 +643,9 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-cells (0.3.8)
rspec-cells (0.3.9)
cells (>= 4.0.0, < 6.0.0)
rspec-rails (>= 3.0.0, < 6.1.0)
rspec-rails (>= 3.0.0, < 6.2.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand Down Expand Up @@ -800,8 +802,8 @@ DEPENDENCIES
bootsnap (~> 1.7)
byebug (~> 11.0)
codecov
decidim (= 0.27.4)
decidim-dev (= 0.27.4)
decidim (= 0.27.5)
decidim-dev (= 0.27.5)
decidim-participatory_documents!
faker (~> 2.14)
letter_opener_web (~> 1.3)
Expand All @@ -816,4 +818,4 @@ RUBY VERSION
ruby 3.0.6p216

BUNDLED WITH
2.4.20
2.4.22
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ Depending on your Decidim version, you can choose the corresponding version to e
## Usage
TODO...
This module adds a new component to Decidim called `Participatory Documents` that allows to upload PDFs and define areas on top of it that will become spaces for suggestions or comments.
The administrator must upload a PDF file and then define areas on top of it by drawing polygons.
Each area will become a new zone that will allow users to create suggestions.
## Configuration
Expand All @@ -66,6 +68,14 @@ Decidim::ParticipatoryDocuments.configure do |config|
end
```
## Antivirus compatibility
This module has a builtin compatibility with https://github.com/mainio/decidim-module-antivirus to scan the uploaded documents (it is also possible to directly use the gem https://github.com/mainio/ratonvirus if configuring it in a initializer).
If the antivirus is not installed, the module will still work but the documents will not be scanned.
> Note: this module only checks for the existance of the class `AntivirusValidator` so it is possible to use any other antivirus validator as well (a custom one for instance).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/openpoke/decidim-module-participatory-documents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ def call
create_document
end
broadcast(:ok, document)
rescue ActiveRecord::RecordInvalid
form.errors.add(:file, document.errors[:file]) if document.errors.include? :file
rescue ActiveRecord::RecordInvalid => e
if document&.errors&.include? :file
form.errors.add(:file, document.errors[:file])
else
form.errors.add(:file, e.message)
end
broadcast(:invalid)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def index

def new
enforce_permission_to :create, :participatory_document
@form = form(DocumentForm).from_params(params)
@form = form(DocumentForm).instance
end

def create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ class DocumentForm < Decidim::Form

attribute :box_color, String, default: "#1e98d7"
attribute :box_opacity, Integer, default: 12
attribute :organization

attribute :file, Decidim::Attributes::Blob
attribute :remove_file, Boolean, default: false

validates :file, passthru: { to: Document }, if: ->(form) { form.file.present? }
validates :file, file_content_type: { allow: ["application/pdf"] }

# ensure color and opacity are present
def map_model(doc)
self.box_color = doc.box_color.presence || "#1e98d7"
self.box_opacity = doc.box_opacity.presence || 12
end

def organization
attributes[:organization] || current_organization
end
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/decidim/participatory_documents/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ class Document < ApplicationRecord

has_one_attached :file
validates_upload :file, uploader: Decidim::ParticipatoryDocuments::PdfDocumentUploader
# compatibility with ratonvirus (see https://github.com/mainio/decidim-module-antivirus)
validates :file, antivirus: true if ParticipatoryDocuments.antivirus_enabled

has_many :sections, class_name: "Decidim::ParticipatoryDocuments::Section", dependent: :restrict_with_error
has_many :suggestions, class_name: "Decidim::ParticipatoryDocuments::Suggestion", dependent: :restrict_with_error, as: :suggestable
has_many :annotations, through: :sections

attr_accessor :remove_file

# the dynamic upload validator requires the organization,
# if the object is not created yet is assigned from the context by the UploadValidationForm using this method
attr_writer :organization

# override the delegate from HasComponent for the dynamic upload validator
def organization
component&.organization || @organization
end

def self.log_presenter_class_for(_log)
Decidim::ParticipatoryDocuments::AdminLog::DocumentPresenter
end
Expand Down
Loading

0 comments on commit 2376bce

Please sign in to comment.