|
|
# Notifications
|
|
|
Project Forum has the ability to send notifications to users after certain actions.
|
|
|
|
|
|
## Notifications in I18n
|
|
|
Notifications are added to the I18n yaml file as follows.
|
|
|
|
|
|
```
|
|
|
notifications:
|
|
|
resource:
|
|
|
action:
|
|
|
as:
|
|
|
subject: 'Subject of email/notification (Plain)'
|
|
|
message: 'Message of notification (HTML)'
|
|
|
setting_group: 'Group the setting belongs to in the notification preferences (Plain)'
|
|
|
setting: 'Textual description of the notification for the notification preferences (Plain)'
|
|
|
```
|
|
|
|
|
|
| **Item** | **Explanation** | **Example** |
|
|
|
| -------- | --------------- | ----------- |
|
|
|
| resource | the resource for which the notification is sent, plural | projects, groups, thesis_projects |
|
|
|
| action | the (HTTP) action executed on the item | create, destroy, update, import |
|
|
|
| as | the name of the notification itself/the person the notification is for | default, thesis_contact, student |
|
|
|
| subject | the subject of the email/notification. Can contain variables (Plaintext) | '%{user} joined your group' |
|
|
|
| message | the message in the email/notification. Can contain variables (HTML) | '%{coach} accepted your invitation <br> Congratulations!' |
|
|
|
| setting_group | the group under which the notification will be listed in the notification preferences (Plaintext) | Project, Group, Coordinator |
|
|
|
| setting | short text describing the notification as shown in the notification preferences (Plaintext) | Coach accepted invitation |
|
|
|
|
|
|
## Notifications in the code (controllers)
|
|
|
To add notifications to a particular controller, add `include Notifyable` to the controller and define a `send_notifications` method as follows.
|
|
|
|
|
|
```
|
|
|
def send_notifications
|
|
|
log_event(
|
|
|
@project,
|
|
|
nil,
|
|
|
additional_param: some_value,
|
|
|
url: url_to_item
|
|
|
).notify(user_or_list_of_users, as: :something)
|
|
|
end
|
|
|
```
|
|
|
|
|
|
If this function is called from the destroy method, then it will look for all the keys under `projects.destroy.something` or, if that does not exist, `projects.default.something`. It will then attempt to send a notification to `user_or_list_of_users`. If the url parameter is given, the notification on Project Forum will include a clickable link to the given url as `view <name of resource>`.
|
|
|
|
|
|
### Variables
|
|
|
Messages can include variables of the form `%{variable_name}`, which are passed to the log_event method as the additional_param values. Each of these params must have a string value.
|
|
|
|
|
|
## Notification Preferences
|
|
|
Notification preferences are automatically generated from the I18n file. They are listed per `setting_group`, with as text `setting`.
|
|
|
|
|
|
![image](uploads/cedf1e0ce98d2fdc99612302969e1ceb/image.png)
|
|
|
|
|
|
So in the above image, there is a setting:
|
|
|
|
|
|
```
|
|
|
notifications:
|
|
|
groups:
|
|
|
create:
|
|
|
coach:
|
|
|
subject: '%{coach} is now a coach of your group'
|
|
|
message: '%{coach} accepted the request to coach your group "%{group}"'
|
|
|
setting_group: 'Group'
|
|
|
setting: 'Coach accepted invitation'
|
|
|
``` |
|
|
\ No newline at end of file |