added authorization and categorizable

This commit is contained in:
Harry Bomrah 2016-07-26 14:32:52 +08:00
parent f0f98f5c09
commit 0a7cac8ee3
7 changed files with 42 additions and 11 deletions

View File

@ -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?

View File

@ -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

View File

@ -1,4 +0,0 @@
module Emailer
module ApplicationHelper
end
end

View File

@ -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

View File

@ -24,6 +24,13 @@
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<!-- Category -->
<div class="control-group">
<label class="control-label muted"><%= t(:category) %></label>
<div class="controls">
<%= select_category(f, @module_app) %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t("emailer.email_to") %></label>
<div class="controls">

View File

@ -13,6 +13,7 @@
<tbody>
<% @emails.each do |email| %>
<tr>
<td><%= email.category.title rescue "" %></td>
<td>
<%= email.mail_subject %>
<div class="quick-edit">
@ -21,7 +22,7 @@
<% if can_edit_or_delete?(email) %>
<li><a href="/admin/emailers/<%=email.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a data-confirm="Are you sure?" data-method="delete" href="/admin/emailers/<%= email.id.to_s %>" class="delete text-error" ><%= t(:delete_) %></a></li>
<% if !email.approved && current_user.is_admin? %>
<% if !email.approved && user_can_approve? %>
<li><a href="/admin/emailers/<%=email.id.to_s%>/approve"><%= t("announcement.approve") %></a>
<% end %>
<% end %>
@ -39,7 +40,7 @@
</td>
</tr>
<tr class="footable-row-detail">
<td class="footable-cell-detail" colspan="4">
<td class="footable-cell-detail" colspan="5">
<div id="<%= "#{email.id.to_s}-detail" %>" class="footable-row-detail-inner" style="display: none;">
<div>
<strong><%= t("emailer.email_to") %></strong> :

View File

@ -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" ,