added approve method to announcements

This commit is contained in:
Harry Bomrah 2014-09-22 16:32:30 +08:00
parent e1a67a2d6f
commit 7552fdd6d0
8 changed files with 52 additions and 4 deletions

View File

@ -3,6 +3,7 @@ class Admin::AnnouncementsController < OrbitAdminController
include Admin::AnnouncementsHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_bulletin, only: [:edit, :destroy]
before_action :load_access_level
def initialize
super
@ -45,11 +46,22 @@ class Admin::AnnouncementsController < OrbitAdminController
bulletin = Bulletin.new(bulletin_params)
bulletin.create_user_id = current_user.id
bulletin.update_user_id = current_user.id
if user_can_approve?
bulletin.approved = true
end
bulletin.save
build_email(bulletin)
redirect_to params['referer_url']
end
def approve_bulletin
id = params[:id]
bulletin = Bulletin.find(id)
bulletin.approved = true
bulletin.save
redirect_to admin_announcements_path
end
def edit
if can_edit_or_delete?(@bulletin)
@tags = @module_app.tags

View File

@ -1,7 +1,7 @@
class AnnouncementsController < ApplicationController
def index
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
anns = announcements.collect do |a|
statuses = a.statuses_with_classname.collect do |status|
@ -49,7 +49,7 @@ class AnnouncementsController < ApplicationController
end
def widget
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
anns = announcements.collect do |a|
statuses = a.statuses_with_classname.collect do |status|
@ -94,7 +94,7 @@ class AnnouncementsController < ApplicationController
end
def widget1
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
anns = announcements.collect do |a|
statuses = a.statuses_with_classname.collect do |status|
@ -144,6 +144,12 @@ class AnnouncementsController < ApplicationController
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
access_level = OrbitHelper.user_access_level?
if !announcement.approved && (access_level != "manager" && access_level != "admin")
return {}
end
tags = announcement.tags.map{|tag| {
"tag" => tag.name ,
"url" => OrbitHelper.page_for_tag(tag)

View File

@ -24,4 +24,24 @@ module Admin::AnnouncementsHelper
ann_page = pages.first if ann_page.nil?
request.protocol+(request.host_with_port+ann_page.url+'/'+bulletin.to_param).gsub('//','/') rescue "/"
end
def load_access_level
if current_user.is_admin?
@access_level = "admin"
elsif current_user.is_manager?(@module_app)
@access_level = "manager"
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

@ -18,6 +18,7 @@ class Bulletin
field :postdate , :type => DateTime, :default => Time.now
field :deadline , :type => DateTime
field :rss2_sn
field :approved, :type => Boolean, :default => false
field :is_preview, :type => Boolean, :default => false
field :email_id
@ -37,6 +38,7 @@ class Bulletin
before_destroy :destroy_email
scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])}
scope :is_approved, ->{where(:approved => true)}
def update_user
User.find(update_user_id) rescue nil

View File

@ -20,6 +20,8 @@
<td>
<% if b.expired? %>
<%= b.title %> <span class='label'><%= t(:expired) %></span>
<% elsif !b.approved? %>
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title %></a> <span class='label'><%= t(:pending) %></span>
<% else %>
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title %></a>
<% end %>
@ -29,6 +31,9 @@
<% if can_edit_or_delete?(b) %>
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% if !b.approved && user_can_approve? %>
<li><a href="<%= admin_announcement_approve_bulletin_path(:id => b.id.to_s) %>"><%= t("announcement.approve") %></a></li>
<% end %>
<% end %>
</ul>
</div>

View File

@ -8,6 +8,7 @@ en:
sub_title: Sub Title
category: Category
add_new: Add New
approve: Approve
all_articles: All Articles
announcement: Announcement
approval_setting: Approval Setting

View File

@ -8,6 +8,7 @@ zh_tw:
sub_title: 副標題
category: 類別
add_new: 新建
approve: 通過
all_articles: 文章列表
announcement: 公告
approval_setting: 審核設定

View File

@ -6,6 +6,7 @@ Rails.application.routes.draw do
namespace :admin do
post 'announcement/preview', to: 'announcements#preview'
get 'announcement/destroy_preview/:slug_title-:uid', to: 'announcements#destroy_preview'
get 'announcement/approve_bulletin', to: 'announcements#approve_bulletin'
resources :announcements
end