diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 98882ec3..1584f512 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -32,13 +32,7 @@ class OrbitBackendController< ApplicationController end def get_sorted_and_filtered(object_class, query=nil) - object_class = object_class.classify.constantize - if query - objects = object_class.all.where(query) - else - objects = object_class.all - end - + objects = get_objects(object_class, query) if !params[:sort].blank? options = params[:sort_options] options = [options] if !options.class.eql?(Array) @@ -157,5 +151,27 @@ class OrbitBackendController< ApplicationController a = params[:direction].eql?('asc') ? (sorted_tmp + sorted_objects) : (sorted_objects + sorted_tmp) a.flatten end + + + def get_viewable(object_class) + objects = get_objects(object_class) + Kaminari.paginate_array(objects).page(params[:page]).per(10) + end + + def get_objects(object_class, query=nil) + + object_class = object_class.classify.constantize + if query + objects = object_class.all.where(query).entries + else + objects = object_class.all.entries + end + if(!is_admin? || !is_manager?) + objects.delete_if{ |object| + (object.is_pending == true) && ((!object.send("#{object.class.to_s.underscore}_category").authed_users('fact_check').include?(current_user) rescue nil) || object.create_user_id!=current_user.id) + } + end + objects + end end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 42b4c8fd..b6566b7e 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -34,7 +34,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10) - @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : Bulletin.all.page(params[:page]).per(10) + @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : get_viewable("bulletin") @bulletin_categories = BulletinCategory.all @bulletin_link = BulletinLink.new @@ -42,12 +42,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin_file = BulletinFile.new @file_url = panel_announcement_back_end_bulletins_path - - if(!is_admin? || !is_manager?) - @bulletins.delete_if{ |bulletin| - bulletin.is_pending == true && ((!bulletin.bulletin_category.authed_users('fact_check').include?(current_user) rescue nil) || bulletin.create_user_id!=current_user.id) - } - end respond_to do |format| format.html # index.html.erb