From c272783f1c72e8a7ad010e1ec19627858b3b5c3c Mon Sep 17 00:00:00 2001 From: yanxd Date: Sat, 7 Dec 2013 10:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=A0=8F=E8=BE=B9=E8=B7=9D?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E8=AE=A8=E8=AE=BA=E5=8C=BA=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=AB=9E=E8=B5=9B=E8=BE=B9=E6=A1=86=E9=A1=B6?= =?UTF-8?q?=E5=87=BA=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 22 +++++++ app/models/forum.rb | 10 +++ app/models/message.rb | 5 +- app/views/bids/_project_list.html.erb | 76 +++++++++++------------ app/views/forums/show.html.erb | 19 +++++- app/views/projects/_tools_expand.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/zh.yml | 1 + 8 files changed, 91 insertions(+), 45 deletions(-) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 35b681c97..8bcc9f387 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -2,6 +2,8 @@ class ForumsController < ApplicationController # GET /forums # GET /forums.json + before_filter :authenticate_user_edit, :only => [:edit, :update] + before_filter :authenticate_user_destroy, :only => [:destroy] def index @offset, @limit = api_offset_and_limit({:limit => 10}) @@ -100,3 +102,23 @@ class ForumsController < ApplicationController end end end + + private + + + def find_forum + @forum = Forum.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + nil + end + + def authenticate_user_edit + find_forum + render_403 unless @forum.editable_by? User.current + end + + def authenticate_user_destroy + find_forum + render_403 unless @forum.destroyable_by? User.current + end \ No newline at end of file diff --git a/app/models/forum.rb b/app/models/forum.rb index 277b55dce..3d4c3830d 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -21,6 +21,16 @@ class Forum < ActiveRecord::Base self.class.reset_counters!(id) end + def editable_by? user + # user && user.logged? || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)) + self.creator == user || user.admin? + end + + def destroyable_by? user + # user && user.logged? && Forum.find(self.forum_id).creator_id == user.id || user.admin? + user.admin? + end + # Updates topic_count, memo_count and last_memo_id attributes for +board_id+ def self.reset_counters!(forum_id) forum_id = forum_id.to_i diff --git a/app/models/message.rb b/app/models/message.rb index a8252df07..b9f71b0ab 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -33,15 +33,14 @@ class Message < ActiveRecord::Base :date_column => "#{table_name}.created_on" acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, :description => :content, - :datetime => :created_on, + # :datetime => "#{Message.table_name}.created_on", :group => :parent, :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})} acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, - :author_key => :author_id, - :timestamp => :created_on + :author_key => :author_id acts_as_watchable validates_presence_of :board, :subject, :content diff --git a/app/views/bids/_project_list.html.erb b/app/views/bids/_project_list.html.erb index e6001590c..2057de64c 100644 --- a/app/views/bids/_project_list.html.erb +++ b/app/views/bids/_project_list.html.erb @@ -1,38 +1,38 @@ - -<%= render_flash_messages %> -<% if @bid.reward_type == 3 %> - <% if User.current.logged?%> - <% if User.current.user_extensions.identity == 1 %> -
-

<%= l(:label_homework_prompt) %>

-

<%= l(:label_homework_prompt_content) %>

-
- <% end %> - <% end %> - - - -
<%= l(:label_homework_project) %>(<%= bidding_project.count%>) - <% if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id = ?',5, 10, 7)).size >0) %> - -
- <%= toggle_link l(:label_commit_homework), 'put-bid-form' %> -
- <% end %> -
- - -<% else %> - - - <% if User.current.logged? %> - - <% end %> -
<%= l(:label_bidding_project) %>(<%= bidding_project.count%>) -
- <%= toggle_link l(:button_bidding), 'put-bid-form' %> -
- - -<% end %> -<%= render :partial=> "list_projects",:locals => {:bidding_project => bidding_project,:bid => @bid }%> + +<%= render_flash_messages %> +<% if @bid.reward_type == 3 %> + <% if User.current.logged?%> + <% if User.current.user_extensions.identity == 1 %> +
+

<%= l(:label_homework_prompt) %>

+

<%= l(:label_homework_prompt_content) %>

+
+ <% end %> + <% end %> + + + +
<%= l(:label_homework_project) %>(<%= bidding_project.count%>) + <% if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id = ?',5, 10, 7)).size >0) %> + +
+ <%= toggle_link l(:label_commit_homework), 'put-bid-form' %> +
+ <% end %> +
+ + +<% else %> + + + <% if User.current.logged? %> + + <% end %> +
<%= l(:label_bidding_project) %>(<%= bidding_project.count%>) +
+ <%= toggle_link l(:button_bidding), 'put-bid-form' %> +
+ + +<% end %> +<%= render :partial=> "list_projects",:locals => {:bidding_project => bidding_project,:bid => @bid }%> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 96f7d2a4b..bb358c99c 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -35,7 +35,20 @@ <%= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add', :onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %> -<% if User.current.admin?||User.current.login==@forum.creator.login %> | -<%= link_to '编辑帖子', edit_forum_path(@forum), :class => 'icon icon-edit' %> -<% end %> + +
+ <%= link_to( + image_tag('edit.png')+l(:label_forum_edit), + {:action => 'edit', :id => @forum}, + :method => 'get', + :title => l(:button_edit) + ) if @forum.editable_by?(User.current) %> + <%= link_to( + image_tag('delete.png')+'删除讨论区', + {:action => 'destroy', :id => @forum}, + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :title => l(:button_delete) + ) if @forum.destroyable_by?(User.current) %> +
<%= render :partial => 'forums/show_topics', :locals => {:memos => @memos} %> diff --git a/app/views/projects/_tools_expand.html.erb b/app/views/projects/_tools_expand.html.erb index d513fa035..e22f7ac9e 100644 --- a/app/views/projects/_tools_expand.html.erb +++ b/app/views/projects/_tools_expand.html.erb @@ -36,7 +36,7 @@ background: url("/images/sidebar/tool_tag_alpha.png") 10px 30% no-repeat transparent; color: #3e3e3e; font-weight: 400; - line-height: 1.2em; + line-height: 1.5em; margin: 0px 0px 10px; padding: 0px 0px 0px 30px; font-size: 1.0em; diff --git a/config/locales/en.yml b/config/locales/en.yml index b0f77be0d..119607aaa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1569,6 +1569,7 @@ en: label_memo_create_fail: Memo was failures created. label_forum_create_succ: Forum was successfully created. label_forum_create_fail: Forum was failures created. + label_forum_edit: Editing forum label_memo_create: publish label_memo_new: new memo label_memo_edit: edit memo diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 96df03e09..ee470d53f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1733,6 +1733,7 @@ zh: label_memo_create_fail: 发布失败 label_forum_create_succ: 贴吧新建成功 label_forum_create_fail: 贴吧新建失败 + label_forum_edit: 编辑讨论区 label_memo_create: 发布 label_memo_new: 新建主题 label_memo_edit: 修改主题