Skip to content

Commit

Permalink
Merge cef971f into b07653b
Browse files Browse the repository at this point in the history
  • Loading branch information
yksflip committed Jul 11, 2023
2 parents b07653b + cef971f commit c15eaf5
Show file tree
Hide file tree
Showing 32 changed files with 177 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Expand Up @@ -49,9 +49,10 @@ RUN export DATABASE_URL=mysql2://localhost/temp?encoding=utf8 && \
rm -Rf /var/lib/apt/lists/* /var/cache/apt/*

# Make relevant dirs and files writable for app user
RUN mkdir -p tmp && \
RUN mkdir -p tmp storage && \
chown nobody config/app_config.yml && \
chown nobody tmp
chown nobody tmp && \
chown nobody storage

# Run app as unprivileged user
USER nobody
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Expand Up @@ -49,6 +49,8 @@ gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb
gem 'exception_notification'
gem 'gaffe'
gem 'hashie', '~> 3.4.6', require: false # https://github.com/westfieldlabs/apivore/issues/114
gem "image_processing", "~> 1.12"
gem "importmap-rails", "~> 1.1"
gem 'midi-smtp-server'
gem 'mime-types'
gem 'recurring_select', git: 'https://github.com/gregschmit/recurring_select'
Expand All @@ -58,6 +60,7 @@ gem 'rswag-api'
gem 'rswag-ui'
gem 'ruby-filemagic'
gem 'spreadsheet'
gem "terser", "~> 1.1"

# we use the git version of acts_as_versioned, and need to include it in this Gemfile
gem 'acts_as_versioned', git: 'https://github.com/technoweenie/acts_as_versioned.git'
Expand Down Expand Up @@ -122,6 +125,3 @@ group :test do
# api
gem 'rswag-specs'
end

gem "importmap-rails", "~> 1.1"
gem "terser", "~> 1.1"
13 changes: 8 additions & 5 deletions Gemfile.lock
Expand Up @@ -254,6 +254,9 @@ GEM
i18n-spec (0.6.0)
iso
ice_cube (0.16.4)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
Expand Down Expand Up @@ -320,8 +323,8 @@ GEM
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitest (5.18.0)
mono_logger (1.1.1)
msgpack (1.6.0)
Expand All @@ -339,9 +342,6 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
Expand Down Expand Up @@ -499,6 +499,8 @@ GEM
ruby-prof (1.4.5)
ruby-progressbar (1.13.0)
ruby-units (3.0.0)
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
Expand Down Expand Up @@ -635,6 +637,7 @@ DEPENDENCIES
i18n-js (~> 3.0.0.rc8)
i18n-spec
ice_cube
image_processing (~> 1.12)
importmap-rails (~> 1.1)
inherited_resources
jquery-rails
Expand Down Expand Up @@ -692,4 +695,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
2.4.13
2.4.5
31 changes: 31 additions & 0 deletions app/assets/stylesheets/actiontext.css
@@ -0,0 +1,31 @@
/*
* Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
* the trix-editor content (whether displayed or under editing). Feel free to incorporate this
* inclusion directly in any other asset bundle and remove this file.
*
*= require trix
*/

/*
* We need to override trix.css’s image gallery styles to accommodate the
* <action-text-attachment> element we wrap around attachments. Otherwise,
* images in galleries will be squished by the max-width: 33%; rule.
*/
.trix-content .attachment-gallery > action-text-attachment,
.trix-content .attachment-gallery > .attachment {
flex: 1 0 33%;
padding: 0 0.5em;
max-width: 33%;
}

.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment,
.trix-content .attachment-gallery.attachment-gallery--2 > .attachment, .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment,
.trix-content .attachment-gallery.attachment-gallery--4 > .attachment {
flex-basis: 50%;
max-width: 50%;
}

.trix-content action-text-attachment .attachment {
padding: 0 !important;
max-width: 100% !important;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -7,4 +7,5 @@
*= require list.unlist
*= require list.missing
*= require recurring_select
*= require actiontext
*/
2 changes: 2 additions & 0 deletions app/javascript/application.js
@@ -1 +1,3 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "trix"
import "@rails/actiontext"
9 changes: 9 additions & 0 deletions app/views/active_storage/blobs/_blob.html.haml
@@ -0,0 +1,9 @@
%figure{class: "attachment attachment--#{blob.representable? ? "preview" : "file"} attachment--#{blob.filename.extension}"}
- if blob.representable?
= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ])
%figcaption.attachment__caption
- if caption = blob.try(:caption)
= caption
- else
%span.attachment__name=link_to blob.filename, blob
%span.attachment__size= number_to_human_size blob.byte_size
3 changes: 3 additions & 0 deletions app/views/layouts/action_text/contents/_content.html.erb
@@ -0,0 +1,3 @@
<div class="trix-content">
<%= yield -%>
</div>
12 changes: 12 additions & 0 deletions app/views/layouts/email.html.haml
@@ -0,0 +1,12 @@
= yield
\
%hr
%ul
%li
%a{href: root_url} Foodsoft
- if FoodsoftConfig[:homepage]
%li
%a{href: FoodsoftConfig[:homepage]} Foodcoop
- if FoodsoftConfig[:help_url]
%li
%a{href: FoodsoftConfig[:help_url]}= t '.help'
3 changes: 3 additions & 0 deletions config/app_config.yml.SAMPLE
Expand Up @@ -173,6 +173,9 @@ default: &defaults
# default to allow automatically adding new articles on sync only when less than 200 articles in total
#shared_supplier_article_sync_limit: 200

# number of days after which attachment files get deleted
#attachement_retention_days: 365

development:
<<: *defaults

Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Expand Up @@ -68,6 +68,8 @@ class Application < Rails::Application
config.active_record.yaml_column_permitted_classes = [Symbol, BigDecimal]

config.autoloader = :zeitwerk

config.active_storage.variant_processor = :mini_magick
end

# Foodsoft version
Expand Down
2 changes: 2 additions & 0 deletions config/importmap.rb
@@ -1,2 +1,4 @@
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
pin "trix"
pin "@rails/actiontext", to: "actiontext.js"
1 change: 1 addition & 0 deletions config/locales/de.yml
Expand Up @@ -1222,6 +1222,7 @@ de:
footer_2_foodsoft: 'Foodsoft: %{url}'
footer_3_homepage: 'Foodcoop: %{url}'
footer_4_help: 'Hilfe: %{url}'
help: 'Hilfe'
foodsoft: Foodsoft
footer:
revision: Revision %{revision}
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -1225,6 +1225,7 @@ en:
footer_2_foodsoft: 'Foodsoft: %{url}'
footer_3_homepage: 'Foodcoop: %{url}'
footer_4_help: 'Help: %{url}'
help: 'Help'
foodsoft: Foodsoft
footer:
revision: revision %{revision}
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Expand Up @@ -1083,6 +1083,7 @@ es:
layouts:
email:
footer_4_help: 'Ayuda: %{url}'
help: 'Ayuda'
footer:
revision: revisión %{revision}
header:
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Expand Up @@ -835,6 +835,7 @@ fr:
email:
footer_3_homepage: 'Boufcoop: %{url}'
footer_4_help: 'Aide: %{url}'
help: 'Aide'
footer:
revision: révision %{revision}
header:
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Expand Up @@ -1195,6 +1195,7 @@ nl:
footer_2_foodsoft: 'Foodsoft: %{url}'
footer_3_homepage: 'Foodcoop: %{url}'
footer_4_help: 'Help: %{url}'
help: 'Help'
foodsoft: Foodsoft
footer:
revision: revisie %{revision}
Expand Down
3 changes: 2 additions & 1 deletion config/schedule.rb
Expand Up @@ -12,9 +12,10 @@
rake 'multicoops:run TASK=foodsoft:import_and_assign_bank_transactions'
end

# Weekly taks
# Weekly tasks
every :sunday, at: '7:14 am' do
rake 'multicoops:run TASK=foodsoft:create_upcoming_periodic_tasks'
rake 'multicoops:run TASKS=foodsoft:prune_old_attachments'
end

# Finish ended orders
Expand Down
27 changes: 27 additions & 0 deletions db/migrate/20230209105256_create_action_text_tables.action_text.rb
@@ -0,0 +1,27 @@
# This migration comes from action_text (originally 20180528164100)
class CreateActionTextTables < ActiveRecord::Migration[6.0]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :action_text_rich_texts, id: primary_key_type do |t|
t.string :name, null: false
t.text :body, size: :long
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type

t.timestamps

t.index [:record_type, :record_id, :name], name: "index_action_text_rich_texts_uniqueness", unique: true
end
end

private

def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end
10 changes: 10 additions & 0 deletions db/migrate/20230215085312_migrate_message_body_to_action_text.rb
@@ -0,0 +1,10 @@
class MigrateMessageBodyToActionText < ActiveRecord::Migration[7.0]
include ActionView::Helpers::TextHelper
def change
rename_column :messages, :body, :body_old
Message.all.each do |message|
message.update_attribute(:body, simple_format(message.body_old))
end
remove_column :messages, :body_old, :text
end
end
13 changes: 11 additions & 2 deletions db/schema.rb
Expand Up @@ -10,7 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_01_06_144440) do
ActiveRecord::Schema[7.0].define(version: 2023_02_15_085312) do
create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "name", null: false
t.text "body", size: :long
t.string "record_type", null: false
t.bigint "record_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end

create_table "active_storage_attachments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -282,7 +292,6 @@
create_table "messages", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
t.integer "sender_id"
t.string "subject", null: false
t.text "body"
t.boolean "private", default: false
t.datetime "created_at", precision: nil
t.integer "reply_to"
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/foodsoft.rake
Expand Up @@ -79,6 +79,19 @@ namespace :foodsoft do
rake_say "#{ba.name}: imported #{importer.count}, assigned #{assign_count}"
end
end

desc 'Prune attachments older than maximum age'
task prune_old_attachments: :environment do
if FoodsoftConfig[:attachement_retention_days]
rake_say "Pruning attachments older than #{FoodsoftConfig[:attachement_retention_days]} days"
ActiveStorage::Attachment.where("created_at < ?", FoodsoftConfig[:attachement_retention_days].days.ago).each do |attachment|
rake_say attachment.inspect
attachment.purge_later
end
else
rake_say "Please configure your app_config.yml accordingly:\nattachement_retention_days: <number of days>"
end
end
end

# Helper
Expand Down
3 changes: 2 additions & 1 deletion plugins/messages/app/controllers/messages_controller.rb
Expand Up @@ -21,7 +21,8 @@ def new
@message.subject = I18n.t('messages.model.reply_subject', subject: original_message.subject)
@message.body = I18n.t('messages.model.reply_header', user: original_message.sender.display,
when: I18n.l(original_message.created_at, format: :short)) + "\n"
original_message.body.each_line { |l| @message.body += I18n.t('messages.model.reply_indent', line: l) }
@message.body = I18n.t('messages.model.reply_header', user: original_message.sender.display, when: I18n.l(original_message.created_at, format: :short)) + "\n" \
+ "<blockquote>" + original_message.body.to_trix_html + "</blockquote>"
else
redirect_to new_message_url, alert: I18n.t('messages.new.error_private')
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/messages/app/helpers/messages_helper.rb
Expand Up @@ -5,7 +5,7 @@ def format_subject(message, length)
body = ''
else
subject = message.subject
body = truncate(message.body, length: length - subject.length)
body = truncate(message.body.to_plain_text, :length => length - subject.length)
end
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe
end
Expand Down
2 changes: 2 additions & 0 deletions plugins/messages/app/models/message.rb
Expand Up @@ -22,6 +22,8 @@ class Message < ApplicationRecord
validates_presence_of :message_recipients, :subject, :body
validates_length_of :subject, in: 1..255

has_rich_text :body

after_initialize do
@recipients_ids ||= []
@send_method ||= 'recipients'
Expand Down
2 changes: 1 addition & 1 deletion plugins/messages/app/views/messages/new.haml
Expand Up @@ -110,7 +110,7 @@
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
= f.input :private, inline_label: t('.hint_private')
= f.input :subject, input_html: {class: 'input-xxlarge'}
= f.input :body, input_html: {class: 'input-xxlarge', rows: 13}
= f.rich_text_area :body, input_html: {class: 'input-xxlarge', rows: 13}
.form-actions
= f.submit class: 'btn btn-primary'
= link_to t('ui.or_cancel'), :back
2 changes: 1 addition & 1 deletion plugins/messages/app/views/messages/show.haml
Expand Up @@ -33,7 +33,7 @@
- if @message.can_toggle_private?(current_user)
= link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini'
%hr/
%p= simple_format(h(@message.body))
.trix-content= @message.body
%hr/
%p
= link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn'
Expand Down
@@ -0,0 +1,11 @@
= raw @message.body
%hr
%ul
- if @message.group
%li= t '.footer_group', group: @message.group.name
%li
%a{href: new_message_url('message[reply_to]' => @message.id)}= t '.reply'
%li
%a{href: message_url(@message)}= t '.see_message_online'
%li
%a{href: my_profile_url}= t '.messaging_options'
3 changes: 3 additions & 0 deletions plugins/messages/config/locales/de.yml
Expand Up @@ -138,6 +138,9 @@ de:
Antworten: %{reply_url}
Nachricht online einsehen: %{msg_url}
Nachrichten-Einstellungen: %{profile_url}
reply: Antworten
see_message_online: Nachricht online einsehen
messaging_options: Nachrichten-Einstellungen
footer_group: |
Gesendet an Gruppe: %{group}
navigation:
Expand Down
3 changes: 3 additions & 0 deletions plugins/messages/config/locales/en.yml
Expand Up @@ -140,6 +140,9 @@ en:
Reply: %{reply_url}
See message online: %{msg_url}
Messaging options: %{profile_url}
reply: Reply
see_message_online: See message online
messaging_options: Messaging options
footer_group: |
Sent to group: %{group}
navigation:
Expand Down

0 comments on commit c15eaf5

Please sign in to comment.