diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index d3a1296..0ef6610 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -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 @@ -41,15 +42,26 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin_params['bulletin_links_attributes'].delete(idx.to_s) if link['url'].blank? end end - + 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 diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 1c421aa..59d331c 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -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) diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index 9a46c72..cf3ace5 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -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 diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 4267639..7f48cbb 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -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 diff --git a/app/views/admin/announcements/_index.html.erb b/app/views/admin/announcements/_index.html.erb index c433d3b..57af791 100644 --- a/app/views/admin/announcements/_index.html.erb +++ b/app/views/admin/announcements/_index.html.erb @@ -20,6 +20,8 @@