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: 修改主题