diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 36b7e8598..c4a03adcf 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -153,6 +153,7 @@ class AdminController < ApplicationController @first_page.image_width = params[:image_width] @first_page.image_height = params[:image_height] @first_page.sort_type = params[:sort_type] + @first_page.show_course = params[:show_course] if @first_page.save respond_to do |format| flash[:notice] = l(:notice_successful_update) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 026a12e9a..36dd61105 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -174,7 +174,9 @@ class AttachmentsController < ApplicationController respond_to do |format| # modify by nwb if !@attachment.container.nil? && (@attachment.container.is_a?(Course) || @attachment.container.course) - if @course.nil? + if @attachment.container.is_a?(News) + format.html { redirect_to_referer_or news_path(@attachment.container) } + elsif @course.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } else format.html { redirect_to_referer_or course_path(@course) } diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f767aed10..eedb29329 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class ProjectsController < ApplicationController layout :select_project_layout + menu_item :overview menu_item :roadmap, :only => :roadmap menu_item :settings, :only => :settings @@ -459,24 +460,10 @@ class ProjectsController < ApplicationController end def new - @project_type = params[:project_type] ||= params[:course] @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all - - case @project_type - when '0' # Project - @project = Project.new - @project.safe_attributes = params[:project] - when '1' # Course - @project = Project.new - @project.safe_attributes = params[:project] - @course_tag = params[:course] - @course = Course.new - @course.safe_attributes = params[:course] - else # default Project - @project = Project.new - @project.safe_attributes = params[:project] - end + @project = Project.new + @project.safe_attributes = params[:project] render :layout => 'base' end @@ -490,128 +477,43 @@ class ProjectsController < ApplicationController end def create - - @course_tag = params[:project][:project_type] - if(@course_tag=="1") - if User.current.user_extensions.identity#.include?(UserExtensions::TEACHER,UserExtensions::DEVELOPER) - @course = Course.new - @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s - @course.safe_attributes = params[:project][:course] - @course.tea_id = User.current.id - # added by bai - @course.term = params[:term] - @course.time = params[:time] - #@course.school_id = params[:occupation] - @course.school_id = User.current.user_extensions.school_id - @course.setup_time = params[:setup_time] - @course.endup_time = params[:endup_time] - @course.class_period = params[:class_period] - end - end @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @project = Project.new - @project.user_id = User.current.id - @project.dts_test = params[:project][:dts_test] @project.safe_attributes = params[:project] - if @course_tag == '1' - @project.identifier = @course.extra - end - if @course_tag == '1' - if User.current.user_extensions.identity == 0 - if@course.save - if validate_parent_id && @project.save - @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - # Add current user as a project member if he is not admin - unless User.current.admin? - r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - m = Member.new(:user => User.current, :roles => [r]) - project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) - user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) - if params[:project][:is_public] == '1' - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :project_type => @course_tag) - end - @project.members << m - @project.project_infos << project - end - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_create) - if params[:continue] - attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} - redirect_to new_project_path(attrs, :course => '0') - #Added by young - - elsif params[:course_continue] - redirect_to new_project_path(:course => '1') - #Ended by young - else - redirect_to settings_project_path(@project,:project_type => 1) - end - } - format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } - end - else - @course.destroy - respond_to do |format| - format.html { render :action => 'new', :layout => 'base'}#Added by young - format.api { render_validation_errors(@project) } - end - end - else - if validate_parent_id && @project.save - @project.delete - respond_to do |format| - format.html { render :action => 'new', :layout => 'base'}#Added by young - format.api { render_validation_errors(@project) } - end + if validate_parent_id && @project.save + @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') + # Add current user as a project member if he is not admin + #unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) + user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) + Rails.logger.debug "UserGrade created: #{user_grades.to_json}" + if params[:project][:is_public] == '1' + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type) + Rails.logger.debug "ProjectStatus created: #{project_status.to_json}" + end + @project.members << m + @project.project_infos << project_info + #end + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} + redirect_to new_project_path(attrs, :course => '0') else - respond_to do |format| - format.html { render :action => 'new', :layout => 'base'}#Added by young - format.api { render_validation_errors(@project) } - end + redirect_to settings_project_path(@project) end - end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } end else - #@project.memberships.create - if validate_parent_id && @project.save - @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - # Add current user as a project member if he is not admin - #unless User.current.admin? - r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - m = Member.new(:user => User.current, :roles => [r]) - project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) - user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) - if params[:project][:is_public] == '1' || @course_tag=="1" - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type) - end - @project.members << m - @project.project_infos << project - #end - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_create) - if params[:continue] - attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} - redirect_to new_project_path(attrs, :course => '0') - #Added by young - - elsif params[:course_continue] - redirect_to new_project_path(:course => '1') - #Ended by young - else - redirect_to settings_project_path(@project) - end - } - format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } - end - else - respond_to do |format| - format.html { render :action => 'new', :layout => 'base'}#Added by young - format.api { render_validation_errors(@project) } - end - end + respond_to do |format| + format.html { render :action => 'new', :layout => 'base'}#Added by young + format.api { render_validation_errors(@project) } + end end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 0cca7be6e..236665b7f 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -24,6 +24,7 @@ class WelcomeController < ApplicationController def index @first_page = FirstPage.where("page_type = 'project'").first + @show_course = @first_page.show_course if @first_page.nil? || @first_page.sort_type.nil? @projects = find_miracle_project(10, 3,"grade desc") else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dbc39f950..50500b40d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -68,6 +68,10 @@ module ApplicationHelper link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) end + def link_to_if_authorized_course(name, options = {}, html_options = nil, *parameters_for_method_reference) + link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_course(options[:controller] || params[:controller], options[:action]) + end + def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference) link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action]) end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4debe668f..c79004794 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -68,6 +68,7 @@ class JournalsForMessage < ActiveRecord::Base return true end end + def self.remove_by_user? user if( self.user == user || @@ -87,6 +88,15 @@ class JournalsForMessage < ActiveRecord::Base def reference_user User.find(reply_id) end + + def delete_by_user?user + # 用户可删除自己的留言 + if self.user.id == user.id || user.admin? + return true + else + return false + end + end def self.reference_message(user_id) @user = User.find(user_id) diff --git a/app/models/project.rb b/app/models/project.rb index d6283e44f..1a2c0504d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -758,6 +758,7 @@ class Project < ActiveRecord::Base 'tracker_ids', 'issue_custom_field_ids', 'project_type', + 'dts_test', 'attachmenttype' diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb index b83e54db1..601b2b8d8 100644 --- a/app/views/admin/first_page_made.html.erb +++ b/app/views/admin/first_page_made.html.erb @@ -27,24 +27,28 @@ <%= text_field_tag 'image_height', params[:label_imgae_height], :value => @first_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>

-

- - - <%= text_area 'first_page', 'description', :value => @first_page.description,:cols => 80, :rows => 15, :class => 'wiki-edit' %> - <%= wikitoolbar_for 'first_page_description' %> -

+ + +

-

+

+ + + <%= text_area 'first_page', 'description', :value => @first_page.description,:cols => 80, :rows => 15, :class => 'wiki-edit' %> + <%= wikitoolbar_for 'first_page_description' %> +

+ <%= submit_tag l(:button_save), :class => "small", :name => nil %> <% end %> diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 52b090bd8..99ecab35d 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -15,7 +15,7 @@ :method => :delete, :class => 'delete', :title => l(:button_delete) %> - <% else %> + <% else %> <%= link_to image_tag('delete.png'), attachment_path(attachment), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, diff --git a/app/views/auto_completes/issues.html.erb b/app/views/auto_completes/issues.html.erb index b097eaff4..1df31e41b 100644 --- a/app/views/auto_completes/issues.html.erb +++ b/app/views/auto_completes/issues.html.erb @@ -1,6 +1,6 @@ <%= raw @issues.map {|issue| { 'id' => issue.id, - 'label' => "#{issue.tracker} ##{issue.id}: #{truncate issue.subject.to_s, :length => 60}", + 'label' => "#{issue.tracker} ##{issue.project_index}: #{truncate issue.subject.to_s, :length => 60}", 'value' => issue.id } }.to_json diff --git a/app/views/courses/feedback.html.erb b/app/views/courses/feedback.html.erb index 90803fdd0..903b0b5fc 100644 --- a/app/views/courses/feedback.html.erb +++ b/app/views/courses/feedback.html.erb @@ -78,6 +78,9 @@ function checkMaxLength() { '#{l(:label_reply_plural)} #{journal.user.name}: '); return false;"} %> <% end %> + <% if journal.delete_by_user?(User.current) %> + <%= link_to(l(:button_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => journal.user}, :method => :delete,:remote => true)%> + <% end %>
diff --git a/app/views/layouts/_base_header.html.erb b/app/views/layouts/_base_header.html.erb index 17f0d1e60..98e14c00a 100644 --- a/app/views/layouts/_base_header.html.erb +++ b/app/views/layouts/_base_header.html.erb @@ -40,8 +40,10 @@
  • <%=link_to_user(User.current)%>