From 0a7cac8ee3d9e9e7e004e59d905f3e41d0e13e87 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 26 Jul 2016 14:32:52 +0800 Subject: [PATCH] added authorization and categorizable --- app/controllers/admin/emailers_controller.rb | 5 ++-- app/helpers/admin/emailers_helper.rb | 24 ++++++++++++++++++++ app/helpers/emailer/application_helper.rb | 4 ---- app/models/email_entry.rb | 3 ++- app/views/admin/emailers/_form.html.erb | 7 ++++++ app/views/admin/emailers/_index.html.erb | 5 ++-- lib/emailer/engine.rb | 5 ++-- 7 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 app/helpers/admin/emailers_helper.rb delete mode 100644 app/helpers/emailer/application_helper.rb diff --git a/app/controllers/admin/emailers_controller.rb b/app/controllers/admin/emailers_controller.rb index ae031aa..36d05b4 100644 --- a/app/controllers/admin/emailers_controller.rb +++ b/app/controllers/admin/emailers_controller.rb @@ -1,7 +1,8 @@ class Admin::EmailersController < OrbitAdminController - + include Admin::EmailersHelper + before_action :load_access_level def index - @table_fields = ["emailer.mail_subject", "emailer.delivery_date", "emailer.created_by", "emailer.status"] + @table_fields = [:category, "emailer.mail_subject", "emailer.delivery_date", "emailer.created_by", "emailer.status"] @emails = EmailEntry.all.order(sort) @emails = search_data(@emails,[:mail_subject]).page(params[:page]).per(10) if request.xhr? diff --git a/app/helpers/admin/emailers_helper.rb b/app/helpers/admin/emailers_helper.rb new file mode 100644 index 0000000..b17c8aa --- /dev/null +++ b/app/helpers/admin/emailers_helper.rb @@ -0,0 +1,24 @@ +module Admin::EmailersHelper + + def load_access_level + if (current_user.is_admin? rescue false) + @access_level = "admin" + elsif (current_user.is_manager?(@module_app) rescue false) + @access_level = "manager" + else + @access_level = "users" + end + end + + def user_can_approve? + case @access_level + when "admin" + return true + when "manager" + return true + else + return false + end + end + +end \ No newline at end of file diff --git a/app/helpers/emailer/application_helper.rb b/app/helpers/emailer/application_helper.rb deleted file mode 100644 index 57c8495..0000000 --- a/app/helpers/emailer/application_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Emailer - module ApplicationHelper - end -end diff --git a/app/models/email_entry.rb b/app/models/email_entry.rb index ff43d83..c10bc5b 100644 --- a/app/models/email_entry.rb +++ b/app/models/email_entry.rb @@ -1,7 +1,8 @@ class EmailEntry include Mongoid::Document include Mongoid::Timestamps - + include OrbitCategory::Categorizable + field :mail_subject #not optional field :mail_content #not optional field :create_user_id diff --git a/app/views/admin/emailers/_form.html.erb b/app/views/admin/emailers/_form.html.erb index 7db61fd..f730ac2 100644 --- a/app/views/admin/emailers/_form.html.erb +++ b/app/views/admin/emailers/_form.html.erb @@ -24,6 +24,13 @@
+ +
+ +
+ <%= select_category(f, @module_app) %> +
+
diff --git a/app/views/admin/emailers/_index.html.erb b/app/views/admin/emailers/_index.html.erb index 7913006..caa569a 100644 --- a/app/views/admin/emailers/_index.html.erb +++ b/app/views/admin/emailers/_index.html.erb @@ -13,6 +13,7 @@ <% @emails.each do |email| %> + <%= email.category.title rescue "" %> <%= email.mail_subject %>
@@ -21,7 +22,7 @@ <% if can_edit_or_delete?(email) %>
  • <%= t(:edit) %>
  • <%= t(:delete_) %>
  • - <% if !email.approved && current_user.is_admin? %> + <% if !email.approved && user_can_approve? %>
  • <%= t("announcement.approve") %> <% end %> <% end %> @@ -39,7 +40,7 @@ - +
    " class="footable-row-detail-inner" style="display: none;">
    <%= t("emailer.email_to") %> : diff --git a/lib/emailer/engine.rb b/lib/emailer/engine.rb index 0043d70..86b69a6 100644 --- a/lib/emailer/engine.rb +++ b/lib/emailer/engine.rb @@ -6,6 +6,7 @@ module Emailer module_label "emailer.emailer" base_url File.expand_path File.dirname(__FILE__) categorizable + authorizable side_bar do head_label_i18n 'emailer.emailer', icon_class: "icons-mail" available_for "users" @@ -21,8 +22,8 @@ module Emailer context_link 'new_', :link_path=>"new_admin_emailer_path" , :priority=>2, - :active_for_action=>{'admin/announcements'=>'new'}, - :available_for => 'users' + :active_for_action=>{'admin/emailers'=>'new'}, + :available_for => 'sub_managers' context_link 'categories', :link_path=>"admin_module_app_categories_path" ,