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
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

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.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 -%>

View File

@ -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
users = self.object_auths.collect{|t| t.auth_users_after_block_list} rescue []
users.flatten!.uniq!
logger.info "Warning calling a auth commend without specificed value( has multi-auths ), return empty"
[]
end
else
self.object_auths.where(title: title).first.auth_users rescue []
end
users
end

View File

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

View File

@ -181,7 +181,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
respond_to do |format|
format.js
end
end
# PUT /bulletins/1
@ -241,7 +240,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end
end
# DELETE /bulletins/1

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
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
key = /#{search}/
find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
else
find(:all).desc( :is_top, :postdate)
end
end
@ -88,6 +79,10 @@ class Bulletin
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

View File

@ -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><%= link_to t(:file), load_quick_edit_panel_announcement_back_end_bulletin_path(bulletin, :type => 'files'), :remote => true %></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_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%></td>

View File

@ -2,7 +2,6 @@
<%= 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>
@ -27,16 +26,11 @@
<% 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>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a
</div>
<% end %>

View File

@ -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%>

View File

@ -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>