Fact check program completed,Lin checked
This commit is contained in:
		
							parent
							
								
									7cc075e124
								
							
						
					
					
						commit
						34a4e47057
					
				| 
						 | 
				
			
			@ -41,6 +41,7 @@ GEM
 | 
			
		|||
    archive-tar-minitar (0.5.2)
 | 
			
		||||
    arel (2.2.3)
 | 
			
		||||
    bcrypt-ruby (3.0.1)
 | 
			
		||||
    bcrypt-ruby (3.0.1-x86-mingw32)
 | 
			
		||||
    brakeman (1.5.1)
 | 
			
		||||
      activesupport
 | 
			
		||||
      erubis (~> 2.6)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
class ObjectAuth  < PrototypeAuth
 | 
			
		||||
  include OrbitCoreLib::ObjectTokenUnility
 | 
			
		||||
  validates_uniqueness_of :obj_authable_type,:scope => :title #{ |c| }
 | 
			
		||||
  validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id]  #{ |c| }
 | 
			
		||||
  belongs_to :obj_authable, polymorphic: true
 | 
			
		||||
  # > - Something.find_with_auth(query)
 | 
			
		||||
  # > - or Something.find(query).auth
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,8 +9,9 @@
 | 
			
		|||
		<%= content_tag :li, link_to(t('admin.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %>
 | 
			
		||||
		<%= content_tag :li, link_to(t('admin.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %>
 | 
			
		||||
		<%= content_tag :li, link_to(t('admin.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('tags', 'index') %>
 | 
			
		||||
		<%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index') %>
 | 
			
		||||
			<%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('tags', 'index')  if is_manager? %>
 | 
			
		||||
	<% end -%>
 | 
			
		||||
 | 
			
		||||
<% end -%>
 | 
			
		||||
 | 
			
		||||
<%= content_tag :li, :class => active_for_controllers('users') do -%>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,11 +21,19 @@ module  OrbitCoreLib
 | 
			
		|||
    
 | 
			
		||||
    def authed_users(title=nil)
 | 
			
		||||
      users = []
 | 
			
		||||
      unless title.nil?
 | 
			
		||||
        users = self.object_auths.where(title: title )[0].auth_users_after_block_list rescue []
 | 
			
		||||
      users = case title
 | 
			
		||||
      when :all
 | 
			
		||||
         ary = self.object_auths.collect{|t| t.auth_users}
 | 
			
		||||
         ary.flatten!
 | 
			
		||||
      when nil
 | 
			
		||||
        if self.object_auths.count ==1 
 | 
			
		||||
          self.object_auths.first.auth_users_after_block_list rescue []
 | 
			
		||||
          else
 | 
			
		||||
            logger.info "Warning calling a auth commend without specificed value( has multi-auths ), return empty"
 | 
			
		||||
            []
 | 
			
		||||
          end
 | 
			
		||||
      else
 | 
			
		||||
        users = self.object_auths.collect{|t| t.auth_users_after_block_list} rescue []
 | 
			
		||||
        users.flatten!.uniq!
 | 
			
		||||
        self.object_auths.where(title: title).first.auth_users rescue []
 | 
			
		||||
      end
 | 
			
		||||
      users
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationController
 | 
			
		||||
class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController
 | 
			
		||||
  
 | 
			
		||||
  layout 'new_admin'
 | 
			
		||||
  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,40 +110,39 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
 | 
			
		|||
 | 
			
		||||
  def link_quick_edit
 | 
			
		||||
	# debugger
 | 
			
		||||
	
 | 
			
		||||
    @bulletin = Bulletin.find(params[:bulletin_id])
 | 
			
		||||
	
 | 
			
		||||
	@link_url = panel_announcement_back_end_bulletin_path(@bulletin)
 | 
			
		||||
	
 | 
			
		||||
    respond_to do |format|
 | 
			
		||||
      format.js
 | 
			
		||||
    end
 | 
			
		||||
	
 | 
			
		||||
  @bulletin = Bulletin.find(params[:bulletin_id])
 | 
			
		||||
	unless  @bulletin.is_expired?
 | 
			
		||||
  	@link_url = panel_announcement_back_end_bulletin_path(@bulletin)
 | 
			
		||||
      respond_to do |format|
 | 
			
		||||
        format.js
 | 
			
		||||
      end	 
 | 
			
		||||
	end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # PUT /bulletins/1
 | 
			
		||||
  # PUT /bulletins/1.xml
 | 
			
		||||
  def update
 | 
			
		||||
    @bulletin = Bulletin.find(params[:id])
 | 
			
		||||
		unless  @bulletin.is_expired?
 | 
			
		||||
      @bulletin.update_user_id = current_user.id
 | 
			
		||||
	
 | 
			
		||||
    @bulletin.update_user_id = current_user.id
 | 
			
		||||
	
 | 
			
		||||
	# @bulletin.image.clear if params[:bulletin][:image_del] == '1'
 | 
			
		||||
	# if params[:bulletin][:image_del] == '1' 
 | 
			
		||||
		# @bulletin.remove_image!
 | 
			
		||||
		# @bulletin.image_del = nil
 | 
			
		||||
		# params[:bulletin][:image_del] = nil
 | 
			
		||||
	# end
 | 
			
		||||
  	# @bulletin.image.clear if params[:bulletin][:image_del] == '1'
 | 
			
		||||
  	# if params[:bulletin][:image_del] == '1' 
 | 
			
		||||
  		# @bulletin.remove_image!
 | 
			
		||||
  		# @bulletin.image_del = nil
 | 
			
		||||
  		# params[:bulletin][:image_del] = nil
 | 
			
		||||
  	# end
 | 
			
		||||
 | 
			
		||||
    respond_to do |format|
 | 
			
		||||
      if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save
 | 
			
		||||
        # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
 | 
			
		||||
        format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
 | 
			
		||||
		format.js  { render 'toggle_enable' }
 | 
			
		||||
        format.xml  { head :ok }
 | 
			
		||||
      else
 | 
			
		||||
        format.html { render :action => "edit" }
 | 
			
		||||
        format.xml  { render :xml => @bulletin.errors, :status => :unprocessable_entity }
 | 
			
		||||
      respond_to do |format|
 | 
			
		||||
        if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save
 | 
			
		||||
          # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
 | 
			
		||||
          format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
 | 
			
		||||
  		format.js  { render 'toggle_enable' }
 | 
			
		||||
          format.xml  { head :ok }
 | 
			
		||||
        else
 | 
			
		||||
          format.html { render :action => "edit" }
 | 
			
		||||
          format.xml  { render :xml => @bulletin.errors, :status => :unprocessable_entity }
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::FactChecksController  < OrbitBackendControll
 | 
			
		|||
    else
 | 
			
		||||
      first_category =  @bulletin_categorys.first
 | 
			
		||||
    end  
 | 
			
		||||
    preload_object_auth = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check')
 | 
			
		||||
    preload_object_auth = first_category.object_auths.where(title: 'fact_check').empty?? (first_category.object_auths.create! :title=> 'fact_check') : first_category.object_auths.where(title: 'fact_check')
 | 
			
		||||
    @users_array =  preload_object_auth.first.privilege_users rescue []
 | 
			
		||||
    respond_to do |format|
 | 
			
		||||
      format.html
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,9 +12,9 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
 | 
			
		|||
  
 | 
			
		||||
    date_now = Time.now
 | 
			
		||||
    if params[:category_id]
 | 
			
		||||
      @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10)
 | 
			
		||||
      @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10)
 | 
			
		||||
    else
 | 
			
		||||
      @bulletins = Bulletin.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10)
 | 
			
		||||
      @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(10)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
	  get_categorys
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
 | 
			
		|||
  end
 | 
			
		||||
  
 | 
			
		||||
  def show
 | 
			
		||||
    @bulletin = Bulletin.find(params[:id])
 | 
			
		||||
    @bulletin = Bulletin.can_display.where.where(_id: params[:id])
 | 
			
		||||
	get_categorys
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,9 +14,9 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
 | 
			
		|||
	# @bulletin_categorys = BulletinCategory.first;
 | 
			
		||||
    # @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9)
 | 
			
		||||
    if params[:category_id]
 | 
			
		||||
      @bulletins = Bulletin.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9)
 | 
			
		||||
      @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9)
 | 
			
		||||
    else
 | 
			
		||||
      @bulletins = Bulletin.widget_datas.limit(9)
 | 
			
		||||
      @bulletins = Bulletin.can_display.widget_datas.limit(9)
 | 
			
		||||
    end
 | 
			
		||||
	
 | 
			
		||||
	get_categorys
 | 
			
		||||
| 
						 | 
				
			
			@ -26,14 +26,14 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
 | 
			
		|||
  def bulletins_and_web_links
 | 
			
		||||
    @tags = AnnouncementTag.all
 | 
			
		||||
    @selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0]
 | 
			
		||||
    @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil
 | 
			
		||||
    @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil
 | 
			
		||||
    @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil
 | 
			
		||||
    render :layout => 'module_widget'
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  def reload_bulletins
 | 
			
		||||
    @selected_tag = AnnouncementTag.find(params[:tag_id])
 | 
			
		||||
    @bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(5) rescue nil
 | 
			
		||||
    @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  def reload_web_links
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,12 +19,14 @@ class Bulletin
 | 
			
		|||
  field :is_top, :type => Boolean, :default => false
 | 
			
		||||
  field :is_hot, :type => Boolean, :default => false
 | 
			
		||||
  field :is_hidden, :type => Boolean, :default => false
 | 
			
		||||
  field :is_checked, :type => Boolean, :default => false 
 | 
			
		||||
  field :is_checked, :type => Boolean, :default => nil 
 | 
			
		||||
  
 | 
			
		||||
  field :not_checked_reason
 | 
			
		||||
  
 | 
			
		||||
  field :public, :type => Boolean, :default => true
 | 
			
		||||
  
 | 
			
		||||
  scope :can_display,where(is_checked: true)
 | 
			
		||||
  
 | 
			
		||||
  mount_uploader :image, ImageUploader
 | 
			
		||||
  
 | 
			
		||||
  belongs_to :bulletin_category
 | 
			
		||||
| 
						 | 
				
			
			@ -47,28 +49,17 @@ class Bulletin
 | 
			
		|||
  
 | 
			
		||||
 | 
			
		||||
  def self.search( search = nil, category_id = nil )
 | 
			
		||||
  
 | 
			
		||||
 if category_id.to_s.size > 0 and search.to_s.size > 0
 | 
			
		||||
 
 | 
			
		||||
    if category_id.to_s.size > 0 and search.to_s.size > 0
 | 
			
		||||
      key = /#{search}/
 | 
			
		||||
 
 | 
			
		||||
   find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate )
 | 
			
		||||
    
 | 
			
		||||
 elsif category_id.to_s.size > 0 and search.to_s.size < 1
 | 
			
		||||
 
 | 
			
		||||
   find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate )
 | 
			
		||||
 
 | 
			
		||||
 elsif search.to_s.size > 0 and category_id.to_s.size < 1
 | 
			
		||||
 
 | 
			
		||||
      find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate )
 | 
			
		||||
    elsif category_id.to_s.size > 0 and search.to_s.size < 1
 | 
			
		||||
      find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate )
 | 
			
		||||
    elsif search.to_s.size > 0 and category_id.to_s.size < 1
 | 
			
		||||
      key = /#{search}/
 | 
			
		||||
   
 | 
			
		||||
   find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
 | 
			
		||||
 else
 | 
			
		||||
   
 | 
			
		||||
   find(:all).desc( :is_top, :postdate)
 | 
			
		||||
   
 | 
			
		||||
 end
 | 
			
		||||
 
 | 
			
		||||
      find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
 | 
			
		||||
    else
 | 
			
		||||
      find(:all).desc( :is_top, :postdate)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -87,7 +78,11 @@ class Bulletin
 | 
			
		|||
   end
 | 
			
		||||
   
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
  def is_expired?
 | 
			
		||||
    Date.today > self.deadline ? true : false  rescue false
 | 
			
		||||
    #some dates might sat as nil so rescue false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def is_top?
 | 
			
		||||
    self.is_top
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +96,15 @@ class Bulletin
 | 
			
		|||
    self.is_hidden
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  def is_checked?
 | 
			
		||||
    self.is_checked
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def is_check_rejected?
 | 
			
		||||
    self.is_checked == false
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  def save_bulletin_links
 | 
			
		||||
	self.bulletin_links.each do |t|
 | 
			
		||||
	  if t.should_destroy
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,8 +10,10 @@
 | 
			
		|||
		<% if bulletin.is_hidden? %>
 | 
			
		||||
			<span class="label"><%= t(:hidden) %></span>
 | 
			
		||||
		<% end %>
 | 
			
		||||
		
 | 
			
		||||
		<div class="quick-edit">
 | 
			
		||||
			<ul class="nav nav-pills hide">
 | 
			
		||||
				<% unless bulletin.is_check_rejected?%>
 | 
			
		||||
				<li><%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(bulletin) %></li>
 | 
			
		||||
				<li class="dropdown">
 | 
			
		||||
					<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t(:quick_edit) %><b class="caret"></b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -23,10 +25,16 @@
 | 
			
		|||
						<li><a href="#" class='toggle-tr-edit' rel='file'><%= t(:file) %></a></li>
 | 
			
		||||
					</ul>
 | 
			
		||||
				</li>
 | 
			
		||||
				<li class="dropdown"><%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(bulletin), :confirm => t('announcement.sure?'), :method => :delete, :remote => true %></li>
 | 
			
		||||
				<%#= debugger  %>
 | 
			
		||||
				<%#= a=1 %>
 | 
			
		||||
				<% if (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager?) and !bulletin.is_expired? %>
 | 
			
		||||
				<li><%= link_to t('bulletin.fact_check'), edit_panel_announcement_back_end_bulletin_path(bulletin)   %></li><%#= #TODO add ancher so user can quick access into that part %>
 | 
			
		||||
				<% end %>				
 | 
			
		||||
				<% end %>
 | 
			
		||||
				<li class="dropdown"><%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(bulletin), :confirm => t('announcement.sure?'), :method => :delete, :remote => true %></li>
 | 
			
		||||
			</ul>
 | 
			
		||||
		</div>
 | 
			
		||||
		
 | 
			
		||||
	</td>
 | 
			
		||||
	<td><%= bulletin.bulletin_category.i18n_variable[I18n.locale] %></td>
 | 
			
		||||
	<td><%= link_to bulletin.title[I18n.locale], panel_announcement_back_end_bulletin_path(bulletin) rescue ''%></td>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
<% # encoding: utf-8 %>
 | 
			
		||||
 | 
			
		||||
		<%= form_for(@bulletin.bulletin_links, :remote => true, :url => @link_url) do |f| %>
 | 
			
		||||
 | 
			
		||||
		<%= form_for(@bulletin.bulletin_links, :remote => true, :url => @link_url)  do |f| %>
 | 
			
		||||
		
 | 
			
		||||
        <div id="modal-link" class="modal hide fade">
 | 
			
		||||
            <div class="modal-header">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@
 | 
			
		|||
 | 
			
		||||
  <%= f.error_messages %>
 | 
			
		||||
  <%= f.select :bulletin_category_id, @bulletin_categorys.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-medium" %>
 | 
			
		||||
 | 
			
		||||
	<% if is_manager? || @bulletin.bulletin_category.authed_users('fact_check').include?(current_user) || current_user.admin?%>
 | 
			
		||||
	<div class="field">
 | 
			
		||||
		<%= label :fact_check_stat, t('announcement.bulletin.fact_check_stat') %>
 | 
			
		||||
		<%= f.radio_button :is_checked, true%> 
 | 
			
		||||
| 
						 | 
				
			
			@ -12,6 +14,8 @@
 | 
			
		|||
		  <%= label :is_checked_false, t('announcement.bulletin.fact_check_not_pass_reason') %>
 | 
			
		||||
		<%= f.text_field :not_checked_reason %>
 | 
			
		||||
	</div>
 | 
			
		||||
	<% end %>
 | 
			
		||||
	
 | 
			
		||||
  <div class="field">
 | 
			
		||||
    <%= f.label :image, t('announcement.image') %><br />
 | 
			
		||||
    <%= f.file_field :image %>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
<% # encoding: utf-8 %>
 | 
			
		||||
 | 
			
		||||
<% if @bulletins and !@bulletins.nil? %>
 | 
			
		||||
 | 
			
		||||
	<h2 class="topic_title"><%= t('announcement.campus_news')%></h2>
 | 
			
		||||
	<%= link_to t('announcement.more'),panel_announcement_front_end_bulletins_path(), :class => "topic_note" %>
 | 
			
		||||
	<div class="topic_prev">previous page</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue