Add only_manager_can_edit_status setting.

This commit is contained in:
BoHung Chiu 2020-05-16 21:43:37 +08:00
parent 5ae0c57a1a
commit 3ed071f486
6 changed files with 33 additions and 10 deletions

View File

@ -15,6 +15,7 @@ class Admin::AnnouncementsController < OrbitAdminController
Bulletin.remove_expired_status
@tags = @module_app.tags
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
@current_user = current_user
if AnnouncementSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app)
current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false
if current_user_is_sub_manager
@ -173,9 +174,15 @@ class Admin::AnnouncementsController < OrbitAdminController
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
end
end
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(current_user.id)
bps[:is_top] = "0"
bps[:top_end_date] = nil
if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) )
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
bps[:is_top] = "0"
bps[:top_end_date] = nil
end
else
bps[:is_top] = false
bps[:is_hot] = false
bps[:is_hidden] = false
end
bulletin = Bulletin.new(bps)
@ -237,12 +244,16 @@ class Admin::AnnouncementsController < OrbitAdminController
bps['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank?
end
end
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
bps[:is_top] = "0"
bps[:top_end_date] = nil
if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) )
if bps[:is_top] == "1" && !AnnouncementSetting.check_limit_for_user(bulletin.create_user_id, bulletin.id)
bps[:is_top] = "0"
bps[:top_end_date] = nil
end
else
bps[:is_top] = bulletin.is_top
bps[:is_hot] = bulletin.is_hot
bps[:is_hidden] = bulletin.is_hidden
end
bulletin.update_attributes(bps)
bulletin.update_user_id = current_user.id
if bulletin.rejected

View File

@ -7,6 +7,7 @@ class AnnouncementSetting
field :approvers, type: Array, :default => []
field :email_to, type: Array, :default => ["admins","managers","approvers"]
field :is_display_edit_only, type: Boolean, :default => false
field :only_manager_can_edit_status, type: Boolean, :default => false
has_many :anns_status_settings, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true
def self.check_limit_for_user(user_id, b_id = nil)

View File

@ -30,7 +30,9 @@
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
<% if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) ) %>
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
<% end %>
<li><a href="#tag" data-toggle="tab"><%= t(:tags) %></a></li>
<li><a href="#imageupload" data-toggle="tab"><%= t('announcement.image') %></a></li>
<li><a href="#mail-group" data-toggle="tab"><%= t('announcement.email_reminder')%></a></li>
@ -97,6 +99,7 @@
</div>
<!-- Status Module -->
<% if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) ) %>
<div class="tab-pane fade" id="status">
<!-- Status -->
<div class="control-group">
@ -138,7 +141,7 @@
</div>
</div>
<%# end %>
<% end %>
<!-- Tag Module -->
<div class="tab-pane fade" id="tag">

View File

@ -121,6 +121,12 @@
<div id="notification"><%= t("announcement.click_on_submit") %></div>
<%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %>
<div class="input-area">
<div class="control-group">
<%= f.label :only_manager_can_edit_status, t("announcement.only_manager_can_edit_status"), :class => "control-label muted" %>
<div class="controls">
<%= f.check_box :only_manager_can_edit_status %>
</div>
</div>
<div class="control-group">
<%= f.label :is_display_edit_only, t("announcement.is_display_edit_only"), :class => "control-label muted" %>
<div class="controls">

View File

@ -114,3 +114,4 @@ en:
display_subtitle: Display Subtitle in Content Page
display_img: Display Cover Image in Content Page
is_display_edit_only: Only display editable announcements
only_manager_can_edit_status: Only manager can edit status of announcements

View File

@ -118,3 +118,4 @@ zh_tw:
display_subtitle: 內容頁顯示副標題
display_img: 內容頁顯示封面圖片
is_display_edit_only: 只顯示可更新的公告
only_manager_can_edit_status: 只有管理者可更新公告狀態