meta_notification 0.0.2
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/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/app/assets/javascripts/meta_notification/application.js +13 -0
- data/app/assets/stylesheets/meta_notification/application.css +15 -0
- data/app/controllers/meta_notification/api/v1/notification_settings_controller.rb +24 -0
- data/app/controllers/meta_notification/api/v1/notification_templates_controller.rb +61 -0
- data/app/controllers/meta_notification/api/v1/notification_types_controller.rb +64 -0
- data/app/controllers/meta_notification/api/v1/notifications_controller.rb +22 -0
- data/app/controllers/meta_notification/api/v1/user_notification_settings_controller.rb +20 -0
- data/app/controllers/meta_notification/api/v1/user_notifications_controller.rb +75 -0
- data/app/controllers/meta_notification/application_controller.rb +4 -0
- data/app/helpers/meta_notification/application_helper.rb +4 -0
- data/app/models/meta_notification/notification.rb +12 -0
- data/app/models/meta_notification/notification_setting.rb +9 -0
- data/app/models/meta_notification/notification_template.rb +17 -0
- data/app/models/meta_notification/notification_type.rb +22 -0
- data/app/models/meta_notification/user_notification.rb +6 -0
- data/app/models/meta_notification/user_notification_setting.rb +10 -0
- data/app/views/layouts/meta_notification/application.html.erb +14 -0
- data/app/views/meta_notification/api/v1/notification_settings/create.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_settings/destroy.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_settings/index.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_settings/show.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_settings/update.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_templates/create.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_templates/destroy.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_templates/index.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_templates/show.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_templates/update.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_types/create.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_types/destroy.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_types/index.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_types/show.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notification_types/update.html.erb +2 -0
- data/app/views/meta_notification/api/v1/notifications/resource_notification.rabl +14 -0
- data/app/views/meta_notification/api/v1/user_notification_settings/create.html.erb +2 -0
- data/app/views/meta_notification/api/v1/user_notification_settings/destroy.html.erb +2 -0
- data/app/views/meta_notification/api/v1/user_notification_settings/index.html.erb +2 -0
- data/app/views/meta_notification/api/v1/user_notification_settings/show.html.erb +2 -0
- data/app/views/meta_notification/api/v1/user_notification_settings/update.html.erb +2 -0
- data/app/views/meta_notification/api/v1/user_notifications/message_notifications.rabl +0 -0
- data/app/views/meta_notification/api/v1/user_notifications/notifications.rabl +21 -0
- data/config/routes.rb +45 -0
- data/db/migrate/20160615074820_create_meta_notification_notification_types.rb +15 -0
- data/db/migrate/20160618094218_create_meta_notification_notification_templates.rb +19 -0
- data/db/migrate/20160619133533_create_meta_notification_notifications.rb +14 -0
- data/db/migrate/20160620015754_create_meta_notification_user_notifications.rb +12 -0
- data/db/migrate/20160620020944_create_meta_notification_notification_settings.rb +10 -0
- data/db/migrate/20160620052742_create_meta_notification_user_notification_settings.rb +12 -0
- data/db/migrate/20160727124414_add_attachment_attachment_to_mn_notifications.rb +11 -0
- data/lib/api_constraints.rb +10 -0
- data/lib/meta_notification/engine.rb +15 -0
- data/lib/meta_notification/version.rb +3 -0
- data/lib/meta_notification.rb +7 -0
- data/lib/meta_notification_authority.rb +39 -0
- data/lib/mn_authorizers/notification_setting_authorizer.rb +28 -0
- data/lib/mn_authorizers/notification_template_authorizer.rb +28 -0
- data/lib/mn_authorizers/notification_type_authorizer.rb +28 -0
- data/lib/mn_authorizers/test_authorizer.rb +11 -0
- data/lib/mn_authorizers/user_notification_authorizer.rb +28 -0
- data/lib/tasks/meta_notification_tasks.rake +4 -0
- data/spec/controllers/meta_notification/api/v1/notification_settings_controller_spec.rb +42 -0
- data/spec/controllers/meta_notification/api/v1/notification_templates_controller_spec.rb +42 -0
- data/spec/controllers/meta_notification/api/v1/notification_types_controller_spec.rb +42 -0
- data/spec/controllers/meta_notification/api/v1/notifications_controller_spec.rb +7 -0
- data/spec/controllers/meta_notification/api/v1/user_notification_settings_controller_spec.rb +42 -0
- data/spec/controllers/meta_notification/api/v1/user_notifications_controller_spec.rb +42 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +33 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +54 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +91 -0
- data/spec/dummy/log/development.log +264 -0
- data/spec/dummy/log/test.log +1192 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/meta_notification/notification_settings.rb +28 -0
- data/spec/factories/meta_notification/notification_templates.rb +59 -0
- data/spec/factories/meta_notification/notification_types.rb +35 -0
- data/spec/factories/meta_notification/notifications.rb +80 -0
- data/spec/factories/meta_notification/user_notification_settings.rb +34 -0
- data/spec/factories/meta_notification/user_notifications.rb +35 -0
- data/spec/models/meta_notification/notification_setting_spec.rb +31 -0
- data/spec/models/meta_notification/notification_spec.rb +39 -0
- data/spec/models/meta_notification/notification_template_spec.rb +37 -0
- data/spec/models/meta_notification/notification_type_spec.rb +36 -0
- data/spec/models/meta_notification/user_notification_setting_spec.rb +31 -0
- data/spec/models/meta_notification/user_notification_spec.rb +28 -0
- data/spec/rails_helper.rb +60 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/views/meta_notification/api/v1/notification_settings/create.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_settings/destroy.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_settings/index.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_settings/show.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_settings/update.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_templates/create.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_templates/destroy.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_templates/index.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_templates/show.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_templates/update.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_types/create.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_types/destroy.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_types/index.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_types/show.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/notification_types/update.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notification_settings/create.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notification_settings/destroy.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notification_settings/index.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notification_settings/show.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notification_settings/update.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notifications/create.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notifications/destroy.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notifications/index.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notifications/show.html.erb_spec.rb +5 -0
- data/spec/views/meta_notification/api/v1/user_notifications/update.html.erb_spec.rb +5 -0
- metadata +355 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fdf25f7aeea42bcd68ab99a3b0ac6181a2358158
|
|
4
|
+
data.tar.gz: a0daee4788f0245bb8572fd55b29dea9516032e4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a700b75f58345cf0ee1d7334b63d150c58f85bb647a851054df467cffb19f8e25bddb5889d2d750a11871dd73d89bbd12eea0b3cddbcd3bfd857739ad96b1538
|
|
7
|
+
data.tar.gz: c3d64d3f5f9b9d2aa79ffb0ff6147100ada18daa587d93c85ecc819541c90e3a309b739bcaa9af56cfc2d858047e5e26950ec598eb5f13fa3f759d15e5c41d86
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2016 Shobhit Dixit
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'MetaNotification'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
load 'rails/tasks/statistics.rake'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Bundler::GemHelper.install_tasks
|
|
26
|
+
|
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
|
28
|
+
|
|
29
|
+
require 'rspec/core'
|
|
30
|
+
require 'rspec/core/rake_task'
|
|
31
|
+
|
|
32
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
|
33
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
|
34
|
+
|
|
35
|
+
task :default => :spec
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_dependency "meta_notification/application_controller"
|
|
2
|
+
|
|
3
|
+
module MetaNotification
|
|
4
|
+
class Api::V1::NotificationSettingsController < ApplicationController
|
|
5
|
+
before_action :init_authorizer
|
|
6
|
+
def index
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def destroy
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def init_authorizer
|
|
21
|
+
@notification_setting_authorizer = NotificationSettingAuthorizer.new
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require_dependency "meta_notification/application_controller"
|
|
2
|
+
require "meta_notification_authority"
|
|
3
|
+
|
|
4
|
+
module MetaNotification
|
|
5
|
+
class Api::V1::NotificationTemplatesController < ApplicationController
|
|
6
|
+
before_action :init_authorizer
|
|
7
|
+
|
|
8
|
+
before_action :set_template, only: [:update, :show]
|
|
9
|
+
|
|
10
|
+
def index
|
|
11
|
+
if MnAuthorizers::NotificationTemplateAuthorizer.readable_by?(current_user)
|
|
12
|
+
@templates = MetaNotification::NotificationTemplate.where(notification_type_id: params[:notification_type_id])
|
|
13
|
+
render :json => @templates.first, status: 200 and return
|
|
14
|
+
end
|
|
15
|
+
render :json => "You are not authorize to complete this action.", status: 422
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# def show
|
|
19
|
+
# render :json => @template
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
# def create
|
|
23
|
+
# @template = MetaNotification::NotificationTemplate.new(template_params)
|
|
24
|
+
# render :json => { errors: @template.errors.messages }, status: 422 and return if @template.errors.present?
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
def update
|
|
28
|
+
if MnAuthorizers::NotificationTemplateAuthorizer.updatable_by?(current_user) && @notification_template_authorizer.updatable_by?(current_user, @template)
|
|
29
|
+
@template.update(template_params[:notification_template])
|
|
30
|
+
render :json => { errors: @template.errors.messages }, status: 422 and return if @template.errors.present?
|
|
31
|
+
render :json => @template, status: 200 and return
|
|
32
|
+
end
|
|
33
|
+
render :json => "You are not authorize to complete this action.", status: 422
|
|
34
|
+
end
|
|
35
|
+
#
|
|
36
|
+
# def destroy
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# def resource_templates
|
|
40
|
+
# @templates = MetaNotification::NotificationTemplate.where(resource_type: params[:resource_type], resource_id: params[:resource_id])
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def set_template
|
|
47
|
+
@template = MetaNotification::NotificationTemplate.find params[:id]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def template_params
|
|
51
|
+
# return params
|
|
52
|
+
params.permit(notification_template: [:in_app, :mobile, :push, :email, :email_subject])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def init_authorizer
|
|
56
|
+
@notification_template_authorizer = MnAuthorizers::NotificationTemplateAuthorizer.new
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private :init_authorizer, :set_template, :template_params
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require_dependency "meta_notification/application_controller"
|
|
2
|
+
require "meta_notification_authority"
|
|
3
|
+
|
|
4
|
+
module MetaNotification
|
|
5
|
+
module Api
|
|
6
|
+
module V1
|
|
7
|
+
class NotificationTypesController < ApplicationController
|
|
8
|
+
include MetaNotificationAuthority
|
|
9
|
+
|
|
10
|
+
before_action :set_type, only: [:update, :show]
|
|
11
|
+
# before_action :authorize
|
|
12
|
+
before_action :init_authorizer
|
|
13
|
+
|
|
14
|
+
# def create
|
|
15
|
+
# if MnAuthorizers::NotificationTypeAuthorizer.creatable?(currrent_user)
|
|
16
|
+
# @type = MetaNotification::NotificationType.create(type_params)
|
|
17
|
+
# render :json => @type
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# def update
|
|
22
|
+
# if @notification_type_authorizer.updtable_by?(current_user, @type)
|
|
23
|
+
# @type.update(type_params)
|
|
24
|
+
# render :json => @type
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
def index
|
|
29
|
+
if MnAuthorizers::NotificationTypeAuthorizer.readable_by?(current_user)
|
|
30
|
+
@types = MetaNotification::NotificationType.all
|
|
31
|
+
render :json => @types
|
|
32
|
+
end
|
|
33
|
+
render :json => "You are not authorize to complete this action.", status: 422
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# def show
|
|
37
|
+
# if @notification_type_authorizer.readable_by?(current_user, @type)
|
|
38
|
+
# render :json => @type
|
|
39
|
+
# end
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
def destroy
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def set_type
|
|
46
|
+
@type = MetaNotification::NotificationType.find params[:id]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def type_params
|
|
50
|
+
# return params
|
|
51
|
+
params.permit(:notification_type)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def init_authorizer
|
|
55
|
+
@notification_type_authorizer = MnAuthorizers::NotificationTypeAuthorizer.new
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private :set_type, :type_params, :init_authorizer
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_dependency "meta_notification/application_controller"
|
|
2
|
+
|
|
3
|
+
module MetaNotification
|
|
4
|
+
class Api::V1::NotificationsController < ApplicationController
|
|
5
|
+
|
|
6
|
+
def resource_notification
|
|
7
|
+
if params[:resource_type].present? && params[:resource_id].present?
|
|
8
|
+
mobile_or_in_app = (params[:platform] == 'mobile') ? 'mobile'.to_sym : 'in_app'.to_sym
|
|
9
|
+
@notifications = MetaNotification::Notification.select("mn_notifications.*", mobile_or_in_app, "mn_notification_types.name", "mn_notification_types.icon", "mn_notification_types.label")
|
|
10
|
+
.joins('JOIN mn_notification_templates on mn_notification_templates.id = mn_notifications.notification_template_id')
|
|
11
|
+
.joins('JOIN mn_notification_types on mn_notification_types.id = mn_notification_templates.notification_type_id')
|
|
12
|
+
.where(resource_type: params[:resource_type], resource_id: params[:resource_id])
|
|
13
|
+
.includes(:users)
|
|
14
|
+
@created_by_users = User.where(id: @notifications.map(&:created_by_id).uniq)
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
# @notifications = MetaNotification::Notification.includes(:users).where(resource_type: params[:resource_type], resource_id: params[:resource_id])
|
|
18
|
+
# @templates = MetaNotification::NotificationTemplate.includes(:notification_type).where(id: @notifications.map(&:notification_template_id).uniq)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_dependency "meta_notification/application_controller"
|
|
2
|
+
|
|
3
|
+
module MetaNotification
|
|
4
|
+
class Api::V1::UserNotificationSettingsController < ApplicationController
|
|
5
|
+
def index
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def update
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def destroy
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_dependency 'meta_notification/application_controller'
|
|
2
|
+
require "meta_notification_authority"
|
|
3
|
+
|
|
4
|
+
module MetaNotification
|
|
5
|
+
module Api
|
|
6
|
+
module V1
|
|
7
|
+
class UserNotificationsController < ApplicationController
|
|
8
|
+
before_action :init_authorizer
|
|
9
|
+
|
|
10
|
+
before_action :set_user_notification, only: [:update, :show]
|
|
11
|
+
before_action :set_notification_type_ids_for_filter, only: [:notifications, :mark_all_read]
|
|
12
|
+
|
|
13
|
+
def show
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def update
|
|
17
|
+
if @user_notifications_authorizer.updatable_by?(current_user, @user_notification)
|
|
18
|
+
@user_notification.update(user_notification_params)
|
|
19
|
+
render :json => {marked: true}, status: 200 and return
|
|
20
|
+
end
|
|
21
|
+
render :json => "You are not authorize to complete this action.", status: 422
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def notifications
|
|
25
|
+
if MnAuthorizers::UserNotificationAuthorizer.readable_by?(current_user, params[:user_id])
|
|
26
|
+
mobile_or_in_app = (params[:platform] == 'mobile') ? 'mobile'.to_sym : 'in_app'.to_sym
|
|
27
|
+
@notifications = MetaNotification::Notification.select(:id, "mn_notifications.*","mn_user_notifications.user_id", mobile_or_in_app, "mn_user_notifications.is_read", "mn_notification_types.name", "mn_notification_types.icon", "mn_notification_types.label", "mn_notifications.created_by_id", "mn_notifications.created_at")
|
|
28
|
+
.joins('JOIN mn_user_notifications on mn_user_notifications.notification_id = mn_notifications.id')
|
|
29
|
+
.joins('JOIN mn_notification_types on mn_notification_types.id = mn_user_notifications.notification_type_id')
|
|
30
|
+
.where("mn_user_notifications.user_id": params[:user_id], "mn_user_notifications.notification_type_id": @notification_type_in_ids)
|
|
31
|
+
.where.not("mn_user_notifications.notification_type_id": @notification_type_not_in_ids)
|
|
32
|
+
@unread_count = @notifications.select { |n| n.is_read == 0 }.length
|
|
33
|
+
@notifications = @notifications.where("mn_user_notifications.is_read": ((params[:is_fetch_unread].try(:to_bool).present?) ? false : [true, false]) )
|
|
34
|
+
@notifications = @notifications.where("mn_notifications.resource_type": params[:resource_type], "mn_notifications.resource_id": params[:resource_id]) if params[:resource_id].present? && params[:resource_type].present?
|
|
35
|
+
@notifications = @notifications.order("mn_notifications.created_at DESC")
|
|
36
|
+
@notifications = @notifications.page(params[:current_page]) if params[:current_page].present?
|
|
37
|
+
|
|
38
|
+
@created_by_users = User.where(id: @notifications.map(&:created_by_id).compact.uniq)
|
|
39
|
+
return
|
|
40
|
+
end
|
|
41
|
+
render :json => "You are not authorize to complete this action.", status: 422
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def mark_all_read
|
|
45
|
+
@user_notifications = MetaNotification::UserNotification.where(user_id: current_user.id, is_read: false, notification_type_id: @notification_type_in_ids)
|
|
46
|
+
.where.not(notification_type_id: @notification_type_not_in_ids)
|
|
47
|
+
@user_notifications.update_all({is_read: true})
|
|
48
|
+
render :json => {marked: true}, status: 200 and return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def destroy
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def set_user_notification
|
|
55
|
+
@user_notification = UserNotification.find params[:id]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def set_notification_type_ids_for_filter
|
|
59
|
+
@notification_type_not_in_ids = (params[:notification_type_not_in].present?) ? MetaNotification::NotificationType.where(name: params[:notification_type_not_in]).pluck(:id) : nil
|
|
60
|
+
@notification_type_in_ids = (params[:notification_type_in].present?) ? MetaNotification::NotificationType.where(name: params[:notification_type_in]).pluck(:id) : MetaNotification::NotificationType.all.pluck(:id)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def user_notification_params
|
|
64
|
+
params.permit(:is_read)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def init_authorizer
|
|
68
|
+
@user_notifications_authorizer = MnAuthorizers::UserNotificationAuthorizer.new
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private :set_user_notification, :user_notification_params, :init_authorizer, :set_notification_type_ids_for_filter
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module MetaNotification
|
|
2
|
+
class Notification < ActiveRecord::Base
|
|
3
|
+
has_attached_file :attachment
|
|
4
|
+
do_not_validate_attachment_file_type :attachment
|
|
5
|
+
|
|
6
|
+
validates_presence_of :notification_template_id, :in_app, :mobile
|
|
7
|
+
|
|
8
|
+
belongs_to :resource, polymorphic: true
|
|
9
|
+
has_many :user_notifications
|
|
10
|
+
has_many :users, through: :user_notifications
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module MetaNotification
|
|
2
|
+
class NotificationSetting < ActiveRecord::Base
|
|
3
|
+
belongs_to :notification_type
|
|
4
|
+
|
|
5
|
+
validates :notification_type_id, presence: true, format: { with: /[0-9]/, message: "only allows integers." }
|
|
6
|
+
validates :is_mute, inclusion: { in: [true, false] }
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module MetaNotification
|
|
2
|
+
class NotificationTemplate < ActiveRecord::Base
|
|
3
|
+
|
|
4
|
+
validates :notification_type_id, presence: true
|
|
5
|
+
validate :presence_of_any_template
|
|
6
|
+
|
|
7
|
+
belongs_to :notification_type
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def presence_of_any_template
|
|
11
|
+
if in_app.blank? && mobile.blank? && push.blank? && email.blank? && sms.blank?
|
|
12
|
+
errors[:base] << "Template for any one or more target is required."
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module MetaNotification
|
|
2
|
+
class NotificationType < ActiveRecord::Base
|
|
3
|
+
|
|
4
|
+
validates :name, :presence => true, :uniqueness => true, :length => {in: 3..256}, format: { with: /\A[a-zA-Z0-9_]+\z/, message: "only allows letters, numbers and underscores" }
|
|
5
|
+
validates :display_name, :length => {maximum: 255}
|
|
6
|
+
|
|
7
|
+
after_create :after_create_notification_type
|
|
8
|
+
|
|
9
|
+
has_many :notification_templates, :dependent => :destroy
|
|
10
|
+
has_one :notification_setting, :dependent => :destroy
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def after_create_notification_type
|
|
15
|
+
# create blank template for the notification type with resource_type/resource_id = nil.
|
|
16
|
+
template = NotificationTemplate.new({notification_type_id: id})
|
|
17
|
+
template.save(validate: false)
|
|
18
|
+
# create notification_settings for the notification type.
|
|
19
|
+
NotificationSetting.create({notification_type_id: id})
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module MetaNotification
|
|
2
|
+
class UserNotificationSetting < ActiveRecord::Base
|
|
3
|
+
belongs_to :notification_type
|
|
4
|
+
belongs_to :user
|
|
5
|
+
|
|
6
|
+
validates :notification_type_id, presence: true, format: { with: /[0-9]/, message: "only allows integers." }
|
|
7
|
+
validates :user_id, presence: true, format: { with: /[0-9]/, message: "only allows integers." }
|
|
8
|
+
validates :is_mute, inclusion: { in: [true, false] }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>MetaNotification</title>
|
|
5
|
+
<%= stylesheet_link_tag "meta_notification/application", media: "all" %>
|
|
6
|
+
<%= javascript_include_tag "meta_notification/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
collection @notifications
|
|
2
|
+
attributes :id, :in_app, :mobile, :label, :icon, :created_at
|
|
3
|
+
node :template_name, &:name
|
|
4
|
+
node :created_by do |notification|
|
|
5
|
+
user = @created_by_users.map { |user| user if notification.created_by_id == user.id }.first
|
|
6
|
+
{ id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name }
|
|
7
|
+
end
|
|
8
|
+
child :users do
|
|
9
|
+
attributes :id, :email, :first_name, :last_name
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
node :attachment do |notification|
|
|
13
|
+
notification.attachment.url if notification.attachment.present?
|
|
14
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
object false
|
|
2
|
+
|
|
3
|
+
child(@notifications => :notifications) do
|
|
4
|
+
attributes :id,:user_id, :is_read, :in_app, :mobile, :label, :icon, :created_at
|
|
5
|
+
node :template_name do |notification|
|
|
6
|
+
notification.name
|
|
7
|
+
end
|
|
8
|
+
node :first_name do |notification|
|
|
9
|
+
@created_by_users.map{|user| user.first_name if notification.created_by_id == user.id}.first
|
|
10
|
+
end
|
|
11
|
+
node :last_name do |notification|
|
|
12
|
+
@created_by_users.map{|user| user.last_name if notification.created_by_id == user.id}.first
|
|
13
|
+
end
|
|
14
|
+
node :attachment do |notification|
|
|
15
|
+
notification.attachment.url if notification.attachment.present?
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
node :unread_count do
|
|
20
|
+
@unread_count
|
|
21
|
+
end
|