Fact check program completed,Lin checked

This commit is contained in:
Matt Fu 2012-03-22 14:33:59 +08:00 committed by Christophe Vilayphiou
parent 7efaddf57c
commit 3ba89ecbcf
13 changed files with 144 additions and 130 deletions

View File

@ -1,6 +1,6 @@
class ObjectAuth < PrototypeAuth class ObjectAuth < PrototypeAuth
include OrbitCoreLib::ObjectTokenUnility 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 belongs_to :obj_authable, polymorphic: true
# > - Something.find_with_auth(query) # > - Something.find_with_auth(query)
# > - or Something.find(query).auth # > - or Something.find(query).auth

View File

@ -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.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.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('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 -%>
<% end -%> <% end -%>
<%= content_tag :li, :class => active_for_controllers('users') do -%> <%= content_tag :li, :class => active_for_controllers('users') do -%>

View File

@ -21,11 +21,19 @@ module OrbitCoreLib
def authed_users(title=nil) def authed_users(title=nil)
users = [] users = []
unless title.nil? users = case title
users = self.object_auths.where(title: title )[0].auth_users_after_block_list rescue [] 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 else
users = self.object_auths.collect{|t| t.auth_users_after_block_list} rescue [] self.object_auths.where(title: title).first.auth_users rescue []
users.flatten!.uniq!
end end
users users
end end

View File

@ -1,4 +1,4 @@
class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationController class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController
layout 'new_admin' layout 'new_admin'

View File

@ -159,12 +159,12 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end end
def file_quick_add def file_quick_add
# debugger # debugger
@bulletin_file = BulletinFile.new @bulletin_file = BulletinFile.new
@file_url = panel_announcement_back_end_bulletins_path @file_url = panel_announcement_back_end_bulletins_path
@bulletin_file.bulletin_id = params[:bulletin_id] @bulletin_file.bulletin_id = params[:bulletin_id]
respond_to do |format| respond_to do |format|
format.js format.js
@ -173,75 +173,73 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end end
def file_quick_edit def file_quick_edit
# debugger # debugger
@bulletin_file = BulletinFile.find(params[:bulletin_id]) @bulletin_file = BulletinFile.find(params[:bulletin_id])
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
respond_to do |format| respond_to do |format|
format.js format.js
end end
end end
# PUT /bulletins/1 # PUT /bulletins/1
# PUT /bulletins/1.xml # PUT /bulletins/1.xml
def update def update
if params[:bulletin_link] if params[:bulletin_link]
@bulletin_link = BulletinLink.find(params[:id]) @bulletin_link = BulletinLink.find(params[:id])
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link) @link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
respond_to do |format| respond_to do |format|
if @bulletin_link.update_attributes(params[:bulletin_link]) if @bulletin_link.update_attributes(params[:bulletin_link])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) } # format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_link' } format.js { render 'update_bulletin_link' }
end end
end end
elsif params[:bulletin_file] elsif params[:bulletin_file]
@bulletin_file = BulletinFile.find(params[:id]) @bulletin_file = BulletinFile.find(params[:id])
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
respond_to do |format| respond_to do |format|
if @bulletin_file.update_attributes(params[:bulletin_file]) if @bulletin_file.update_attributes(params[:bulletin_file])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) } # format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_file' } format.js { render 'update_bulletin_file' }
end end
end end
else else
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
@bulletin.update_user_id = current_user.id @bulletin.update_user_id = current_user.id
# @bulletin.image.clear if params[:bulletin][:image_del] == '1' # @bulletin.image.clear if params[:bulletin][:image_del] == '1'
# if params[:bulletin][:image_del] == '1' # if params[:bulletin][:image_del] == '1'
# @bulletin.remove_image! # @bulletin.remove_image!
# @bulletin.image_del = nil # @bulletin.image_del = nil
# params[:bulletin][:image_del] = nil # params[:bulletin][:image_del] = nil
# end # end
respond_to do |format| respond_to do |format|
if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save 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_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.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
format.js { render 'toggle_enable' } format.js { render 'toggle_enable' }
format.xml { head :ok } format.xml { head :ok }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
end end
end end
end end
end end
# DELETE /bulletins/1 # DELETE /bulletins/1

View File

@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::FactChecksController < OrbitBackendControll
else else
first_category = @bulletin_categorys.first first_category = @bulletin_categorys.first
end 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 [] @users_array = preload_object_auth.first.privilege_users rescue []
respond_to do |format| respond_to do |format|
format.html format.html

View File

@ -12,9 +12,9 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
date_now = Time.now date_now = Time.now
if params[:category_id] 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 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 end
get_categorys get_categorys
@ -23,7 +23,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
end end
def show def show
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.can_display.where.where(_id: params[:id])
get_categorys get_categorys
end end

View File

@ -14,9 +14,9 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
# @bulletin_categorys = BulletinCategory.first; # @bulletin_categorys = BulletinCategory.first;
# @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9) # @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9)
if params[:category_id] 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 else
@bulletins = Bulletin.widget_datas.limit(9) @bulletins = Bulletin.can_display.widget_datas.limit(9)
end end
get_categorys get_categorys
@ -26,14 +26,14 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
def bulletins_and_web_links def bulletins_and_web_links
@tags = AnnouncementTag.all @tags = AnnouncementTag.all
@selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0] @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 @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil
render :layout => 'module_widget' render :layout => 'module_widget'
end end
def reload_bulletins def reload_bulletins
@selected_tag = AnnouncementTag.find(params[:tag_id]) @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 end
def reload_web_links def reload_web_links

View File

@ -19,12 +19,14 @@ class Bulletin
field :is_top, :type => Boolean, :default => false field :is_top, :type => Boolean, :default => false
field :is_hot, :type => Boolean, :default => false field :is_hot, :type => Boolean, :default => false
field :is_hidden, :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 :not_checked_reason
field :public, :type => Boolean, :default => true field :public, :type => Boolean, :default => true
scope :can_display,where(is_checked: true)
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader
belongs_to :bulletin_category belongs_to :bulletin_category
@ -47,28 +49,17 @@ class Bulletin
def self.search( search = nil, category_id = nil ) 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}/ key = /#{search}/
find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate )
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 category_id.to_s.size > 0 and search.to_s.size < 1 elsif search.to_s.size > 0 and category_id.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}/ key = /#{search}/
find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) else
else find(:all).desc( :is_top, :postdate)
end
find(:all).desc( :is_top, :postdate)
end
end end
@ -88,6 +79,10 @@ 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? def is_top?
self.is_top self.is_top
@ -101,6 +96,15 @@ class Bulletin
self.is_hidden self.is_hidden
end end
def is_checked?
self.is_checked
end
def is_check_rejected?
self.is_checked == false
end
def save_bulletin_links def save_bulletin_links
self.bulletin_links.each do |t| self.bulletin_links.each do |t|
if t.should_destroy if t.should_destroy

View File

@ -10,8 +10,10 @@
<% if bulletin.is_hidden? %> <% if bulletin.is_hidden? %>
<span class="label"><%= t(:hidden) %></span> <span class="label"><%= t(:hidden) %></span>
<% end %> <% end %>
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills hide"> <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><%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(bulletin) %></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t(:quick_edit) %><b class="caret"></b></a> <a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t(:quick_edit) %><b class="caret"></b></a>
@ -23,10 +25,16 @@
<li><%= link_to t(:file), load_quick_edit_panel_announcement_back_end_bulletin_path(bulletin, :type => 'files'), :remote => true %></li> <li><%= link_to t(:file), load_quick_edit_panel_announcement_back_end_bulletin_path(bulletin, :type => 'files'), :remote => true %></li>
</ul> </ul>
</li> </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 %> <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> </ul>
</div> </div>
</td> </td>
<td><%= bulletin.bulletin_category.i18n_variable[I18n.locale] %></td> <td><%= bulletin.bulletin_category.i18n_variable[I18n.locale] %></td>
<td><%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%></td> <td><%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%></td>

View File

@ -1,43 +1,37 @@
<% # encoding: utf-8 %> <% # encoding: utf-8 %>
<%= form_for(@bulletin_link, :remote => true, :url => @link_url) do |f| %> <%= form_for(@bulletin_link, :remote => true, :url => @link_url) do |f| %>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= (@bulletin_link.new_record? ? 'Add Link' : 'Edit Link') %></h3>
</div>
<div class="modal-body form-horizontal">
<div class="control-group">
<label for="http" class="control-label">URL</label>
<div class="controls">
<%= f.text_field :url %>
</div>
</div>
<%= f.fields_for :i18n_variable, (@bulletin_link.new_record? ? @bulletin_link.build_i18n_variable : @bulletin_link.i18n_variable) do |f| %>
<% @site_valid_locales.each do |locale| %>
<div class="control-group">
<%= label_tag "link-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %>
<div class="controls">
<%#= f.text_field locale, :class => 'input-xxlarge' %>
<%= f.text_field locale %>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="modal-footer">
<%= hidden_field_tag 'bulletin_link[bulletin_id]', @bulletin_link.bulletin_id %>
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a>
</div>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= (@bulletin_link.new_record? ? 'Add Link' : 'Edit Link') %></h3>
</div>
<div class="modal-body form-horizontal">
<div class="control-group">
<label for="http" class="control-label">URL</label>
<div class="controls">
<%= f.text_field :url %>
</div>
</div>
<%= f.fields_for :i18n_variable, (@bulletin_link.new_record? ? @bulletin_link.build_i18n_variable : @bulletin_link.i18n_variable) do |f| %>
<% @site_valid_locales.each do |locale| %>
<div class="control-group">
<%= label_tag "link-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %>
<div class="controls">
<%#= f.text_field locale, :class => 'input-xxlarge' %>
<%= f.text_field locale %>
</div>
</div>
<% end %> <% end %>
<% end %>
<div class="modal-footer">
<%= hidden_field_tag 'bulletin_link[bulletin_id]', @bulletin_link.bulletin_id %>
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a
</div>
<% end %>

View File

@ -2,6 +2,8 @@
<%= f.error_messages %> <%= f.error_messages %>
<%= f.select :bulletin_category_id, @bulletin_categorys.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-medium" %> <%= 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"> <div class="field">
<%= label :fact_check_stat, t('announcement.bulletin.fact_check_stat') %> <%= label :fact_check_stat, t('announcement.bulletin.fact_check_stat') %>
<%= f.radio_button :is_checked, true%> <%= f.radio_button :is_checked, true%>

View File

@ -1,7 +1,6 @@
<% # encoding: utf-8 %> <% # encoding: utf-8 %>
<% if @bulletins and !@bulletins.nil? %> <% if @bulletins and !@bulletins.nil? %>
<h2 class="topic_title"><%= t('announcement.campus_news')%></h2> <h2 class="topic_title"><%= t('announcement.campus_news')%></h2>
<%= link_to t('announcement.more'),panel_announcement_front_end_bulletins_path(), :class => "topic_note" %> <%= link_to t('announcement.more'),panel_announcement_front_end_bulletins_path(), :class => "topic_note" %>
<div class="topic_prev">previous page</div> <div class="topic_prev">previous page</div>