diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 6f1b36e..3f682c5 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -4,7 +4,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 + before_action :load_access_level, :load_settings def initialize super @@ -38,10 +38,7 @@ class Admin::AnnouncementsController < OrbitAdminController end def settings - @setting = AnnouncementSetting.first rescue nil - if @setting.nil? - @setting = AnnouncementSetting.new - end + @setting = @announcement_setting end def import @@ -86,7 +83,7 @@ class Admin::AnnouncementsController < OrbitAdminController end def updatesettings - setting = AnnouncementSetting.first + setting = @announcement_setting setting.update_attributes(settings_params) setting.save redirect_to admin_announcement_settings_path @@ -339,6 +336,13 @@ class Admin::AnnouncementsController < OrbitAdminController private + def load_settings + @announcement_setting = AnnouncementSetting.first rescue nil + if @announcement_setting.nil? + @announcement_setting = AnnouncementSetting.create + end + end + def set_bulletin @bulletin = Bulletin.find(params[:id]) end diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 5ea0170..4342852 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -255,7 +255,9 @@ class AnnouncementsController < ApplicationController access_level = OrbitHelper.user_access_level? if !announcement.approved && (access_level != "manager" && access_level != "admin") - return {} + if !(access_level == "sub_manager" && AnnouncementSetting.first.approvers.include?(OrbitHelper.current_user.id.to_s)) + return {} + end end return {} if announcement.category.disable diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index cc0357e..4fc728f 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -133,14 +133,23 @@ module Admin::AnnouncementsHelper end def send_notification_mail_to_managers(announcement, type) - authorizations = Authorization.where(:module_app_id => @module_app.id) - users = authorizations.collect do |auth| - auth.user + users = [] + if @announcement_setting.email_to.include?("managers") + authorizations = Authorization.where(:module_app_id => @module_app.id) + users = authorizations.collect do |auth| + auth.user + end + end + if @announcement_setting.email_to.include?("admins") + wg = Workgroup.where(:key => "admin").first + admins = User.where(:workgroup_id => wg.id) + users.delete(nil) + users = users.concat(admins.to_a) + end + if @announcement_setting.email_to.include?("approvers") + approvers = User.find(@announcement_setting.approvers) rescue [] + users = users.concat(approvers.to_a) end - wg = Workgroup.where(:key => "admin").first - admins = User.where(:workgroup_id => wg.id) - users.delete(nil) - users = users.concat(admins.to_a) users.each do |user| email = user.member_profile.email if !email.nil? && email != "" @@ -210,15 +219,29 @@ module Admin::AnnouncementsHelper end end - def user_can_approve? + def user_can_approve?(anns=nil) + can_approve = false + setting = AnnouncementSetting.first case @access_level when "admin" - return true + can_approve = true when "manager" - return true + can_approve = true else - return false + can_approve = false end + if !can_approve + if !anns.nil? + if setting.approvers.include?(current_user.id.to_s) + if (current_user.approved_categories_for_module(@module_app).include?(anns.category) rescue false) + can_approve = true + end + end + else + can_approve = setting.approvers.include?(current_user.id.to_s) + end + end + can_approve end end diff --git a/app/models/announcement_setting.rb b/app/models/announcement_setting.rb index 041f100..112c486 100644 --- a/app/models/announcement_setting.rb +++ b/app/models/announcement_setting.rb @@ -4,6 +4,8 @@ class AnnouncementSetting field :top_limit, type: Integer, :default => 0 field :pro_enabled, type: Boolean, :default => false + field :approvers, type: Array, :default => [] + field :email_to, type: Array, :default => ["admins","managers","approvers"] def self.check_limit_for_user(user_id, b_id = nil) limit = self.first.top_limit rescue 0 diff --git a/app/views/admin/announcements/_index.html.erb b/app/views/admin/announcements/_index.html.erb index d352938..3510c4c 100644 --- a/app/views/admin/announcements/_index.html.erb +++ b/app/views/admin/announcements/_index.html.erb @@ -48,9 +48,9 @@ <% if can_edit_or_delete?(b) %>