-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add email notifications for file updates
- Loading branch information
1 parent
6399829
commit 5009113
Showing
50 changed files
with
361 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ sharing files in a web browser. It lets users | |
- share files | ||
- search folders and files | ||
- sort files and folders | ||
- notify by email when files in specific folders are created, updated or removed | ||
|
||
Admins can: | ||
- manage users | ||
|
@@ -44,6 +45,7 @@ Boxroom.configure do |config| | |
config.show_settings = true | ||
config.show_shared_files = true | ||
config.show_search = true | ||
config.enable_notifications = true # notify by email when files in specific folders are created, updated or removed | ||
end | ||
``` | ||
|
||
|
@@ -71,9 +73,83 @@ end | |
``` | ||
- if you modify your users without callbacks in any place you should also take care of `boxroom_users` table yourself. | ||
|
||
## Contributing | ||
## Mail settings | ||
|
||
Boxroom sends email on the following occasions: | ||
|
||
* When inviting new users | ||
* On a reset password request | ||
* When a file is shared | ||
|
||
For the application to be able to send email, a few things have to be set up. Depending on the environment | ||
you're working in, either open `config/environments/development.rb` or `config/environments/production.rb`. | ||
Uncomment the following lines and fill in the correct settings of your mail server: | ||
|
||
```ruby | ||
config.action_mailer.delivery_method = :smtp | ||
config.action_mailer.smtp_settings = { | ||
address: 'mailhost', | ||
port: 587, | ||
user_name: 'user_name', | ||
password: 'password', | ||
authentication: 'plain' | ||
} | ||
``` | ||
|
||
Also uncomment the following and replace `localhost:3000` with the host name the app will be running under: | ||
|
||
```ruby | ||
config.action_mailer.default_url_options = { host: 'localhost:3000' } | ||
``` | ||
|
||
Lastly, you have to choose the address emails will be sent from. You can do | ||
this by uncommenting and adjusting the following: | ||
|
||
```ruby | ||
ActionMailer::Base.default from: 'Boxroom <[email protected]>' | ||
``` | ||
|
||
|
||
## Languages | ||
|
||
Thanks to [Rob Halff](https://github.com/rhalff), [Marcus Ilgner](https://github.com/milgner), | ||
[Jessica Marcon](https://github.com/marcontwm), [Arnaud Sellenet](https://github.com/demental), | ||
[Burnaby John](https://github.com/john-coding) and [marcosantoniocaro](https://github.com/marcosantoniocaro) | ||
Boxroom is now available in Dutch, German, Italian, French, Simplified Chinese and Spanish. | ||
|
||
English is the default. To change the language, open `config/application.rb` and set the language you desire: | ||
|
||
```ruby | ||
config.i18n.default_locale = :en # English | ||
config.i18n.default_locale = :nl # Dutch | ||
config.i18n.default_locale = :de # German | ||
config.i18n.default_locale = :it # Italian | ||
config.i18n.default_locale = :fr # French | ||
config.i18n.default_locale = :'zh-CN' # Simplified Chinese | ||
config.i18n.default_locale = :es # Spanish | ||
``` | ||
|
||
It would be great to have many more languages. I am waiting for your pull requests. | ||
|
||
## Contributing and Development | ||
Please feel free to leave an issue or PR. | ||
|
||
- Use `docker-compose up -d` to launch mailcatcher on [http://localhost:1080](http://localhost:1080) | ||
- Update mail settings in `config/environments/development.rb` | ||
```ruby | ||
config.action_mailer.raise_delivery_errors = true | ||
config.action_mailer.perform_caching = false | ||
config.action_mailer.perform_deliveries = true | ||
config.action_mailer.delivery_method = :smtp | ||
config.action_mailer.smtp_settings = { | ||
address: 'localhost', | ||
port: 1025 | ||
} | ||
config.action_mailer.default_url_options = { :host => 'localhost:3000' } | ||
|
||
ActionMailer::Base.default from: 'Boxroom <[email protected]>' | ||
``` | ||
|
||
## Testing | ||
- run migrations `bin/rails db:migrate RAILS_ENV=test` | ||
- run tests `bin/rails test` | ||
|
@@ -82,6 +158,7 @@ Please feel free to leave an issue or PR. | |
The engine is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). | ||
|
||
## Roadmap: | ||
- tests for notifications | ||
- support s3 | ||
- batch actions | ||
- tag files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Boxroom::UserFile::Contract | ||
class Notify < Reform::Form | ||
property :id, virtual: true | ||
|
||
validates :id, presence: true | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
app/concepts/boxroom/user_file/operations/notify_create.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Boxroom | ||
class UserFile < ActiveRecord::Base | ||
class NotifyCreate < ::Trailblazer::Operation | ||
step Trailblazer::Operation::Contract::Build(constant: Boxroom::UserFile::Contract::Notify) | ||
step Trailblazer::Operation::Contract::Validate() | ||
step :model! | ||
step :check | ||
step :notify | ||
|
||
def model!(options, params:, **) | ||
options['model'] = UserFile.find(params[:id]) | ||
end | ||
|
||
def check(options, params:, **) | ||
return false unless Boxroom.configuration.enable_notifications | ||
return false unless options['model'].folder.notify_create | ||
true | ||
end | ||
|
||
def notify(options, params:, **) | ||
options['model'].folder.notify_emails.gsub(',', ' ').split.each do |email| | ||
UserFileMailer.notify_create(options['model'], email).deliver_later | ||
end | ||
end | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
app/concepts/boxroom/user_file/operations/notify_remove.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Boxroom | ||
class UserFile < ActiveRecord::Base | ||
class NotifyRemove < ::Trailblazer::Operation | ||
step Trailblazer::Operation::Contract::Build(constant: Boxroom::UserFile::Contract::Notify) | ||
step Trailblazer::Operation::Contract::Validate() | ||
step :model! | ||
step :check | ||
step :notify | ||
|
||
def model!(options, params:, **) | ||
options['model'] = UserFile.find(params[:id]) | ||
end | ||
|
||
def check(options, params:, **) | ||
return false unless Boxroom.configuration.enable_notifications | ||
return false unless options['model'].folder.notify_remove | ||
true | ||
end | ||
|
||
def notify(options, params:, **) | ||
options['model'].folder.notify_emails.gsub(',', ' ').split.each do |email| | ||
UserFileMailer.notify_remove(options['model'].attachment_file_name, options['model'].folder, email).deliver_later | ||
end | ||
end | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
app/concepts/boxroom/user_file/operations/notify_update.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Boxroom | ||
class UserFile < ActiveRecord::Base | ||
class NotifyUpdate < ::Trailblazer::Operation | ||
step Trailblazer::Operation::Contract::Build(constant: Boxroom::UserFile::Contract::Notify) | ||
step Trailblazer::Operation::Contract::Validate() | ||
step :model! | ||
step :check | ||
step :notify | ||
|
||
def model!(options, params:, **) | ||
options['model'] = UserFile.find(params[:id]) | ||
end | ||
|
||
def check(options, params:, **) | ||
return false unless Boxroom.configuration.enable_notifications | ||
return false unless options['model'].folder.notify_update | ||
true | ||
end | ||
|
||
def notify(options, params:, **) | ||
options['model'].folder.notify_emails.gsub(',', ' ').split.each do |email| | ||
UserFileMailer.notify_update(options['model'], email).deliver_later | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Boxroom | ||
class UserFileMailer < ActionMailer::Base | ||
def notify_create(user_file, email) | ||
@user_file = user_file | ||
mail(to: email, subject: t(:file_added)) | ||
end | ||
|
||
def notify_update(user_file, email) | ||
@user_file = user_file | ||
mail(to: email, subject: t(:file_updated)) | ||
end | ||
|
||
def notify_remove(file_name, folder, email) | ||
@file_name = file_name | ||
@folder = folder | ||
mail(to: email, subject: t(:file_removed)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.