diff --git a/Gemfile b/Gemfile index 634af9683..e5f2a7054 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source 'https://ruby.taobao.org' unless RUBY_PLATFORM =~ /w32/ # unix-like only @@ -19,19 +19,34 @@ gem 'acts-as-taggable-on', '2.4.1' group :development do gem 'better_errors', path: 'lib/better_errors' gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' - if ENV['PRY'] - gem 'pry' - gem 'pry-nav' - end end group :test do - # shoulda的版本做了改动 #gem "shoulda", "~> 3.3.2" gem "shoulda", "> 3.3.2" gem "mocha", "~> 0.13.3" gem 'capybara', '~> 2.0.0' gem 'nokogiri', '< 1.6.0' + gem 'factory_girl' + + platforms :mri, :mingw do + group :rmagick do + # RMagick 2 supports ruby 1.9 + # RMagick 1 would be fine for ruby 1.8 but Bundler does not support + # different requirements for the same gem on different platforms + gem "rmagick", ">= 2.0.0" + end + end +end + +group :development, :test do + gem "guard-rails" + gem 'spork-testunit' + gem 'guard-spork' + gem 'guard-test', '~> 1.0.0' + gem 'ruby-prof' unless RUBY_PLATFORM =~ /w32/ + gem 'pry' + gem 'pry-nav' end @@ -53,15 +68,6 @@ group :ldap do end -platforms :mri, :mingw do - group :rmagick do - # RMagick 2 supports ruby 1.9 - # RMagick 1 would be fine for ruby 1.8 but Bundler does not support - # different requirements for the same gem on different platforms - gem "rmagick", ">= 2.0.0" - end -end - # Optional gem for OpenID authentication group :openid do gem "ruby-openid", "~> 2.1.4", :require => "openid" diff --git a/Gemfile.lock b/Gemfile.lock index d30eb7bc4..4159a32a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,7 +19,7 @@ PATH rails GEM - remote: https://rubygems.org/ + remote: https://ruby.taobao.org/ remote: https://rubygems.org/ specs: actionmailer (3.2.13) @@ -51,7 +51,7 @@ GEM multi_json (~> 1.0) acts-as-taggable-on (2.4.1) rails (>= 3, < 5) - arel (3.0.2) + arel (3.0.3) builder (3.0.0) capybara (2.0.3) mime-types (>= 1.16) @@ -60,6 +60,8 @@ GEM rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 1.0.0) + celluloid (0.15.2) + timers (~> 1.1.0) childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) climate_control (0.0.3) @@ -70,14 +72,33 @@ GEM coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) - coffee-script (2.2.0) + coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.7.0) + coffee-script-source (1.7.1) erubis (2.7.0) - execjs (2.0.2) - fastercsv (1.5.0) + execjs (2.2.1) + factory_girl (4.4.0) + activesupport (>= 3.0.0) + fastercsv (1.5.5) + ffi (1.9.3) ffi (1.9.3-x86-mingw32) + formatador (0.2.5) + guard (2.6.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + pry (>= 0.9.12) + thor (>= 0.18.1) + guard-rails (0.5.2) + guard (~> 2.0) + guard-spork (1.5.1) + childprocess (>= 0.2.3) + guard (>= 1.1) + spork (>= 0.8.4) + guard-test (1.0.0) + guard (>= 1.8) + test-unit (~> 2.2) hike (1.2.3) htmlentities (4.3.2) i18n (0.6.1) @@ -85,36 +106,56 @@ GEM jquery-rails (2.0.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.8.0) + json (1.8.1) kaminari (0.16.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) + libv8 (3.16.14.3) + listen (2.7.9) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + lumberjack (1.0.9) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.4) - mime-types (1.23) + method_source (0.8.2) + mime-types (1.25.1) mocha (0.13.3) metaclass (~> 0.0.1) - multi_json (1.7.6) + multi_json (1.10.1) + mysql2 (0.3.11) mysql2 (0.3.11-x86-mingw32) net-ldap (0.3.1) + nokogiri (1.5.11) nokogiri (1.5.11-x86-mingw32) paperclip (3.5.4) activemodel (>= 3.0.0) activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types - polyglot (0.3.3) + polyglot (0.3.5) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + pry (0.9.12.6-x86-mingw32) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + win32console (~> 1.3) + pry-nav (0.2.3) + pry (~> 0.9.10) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-openid (1.3.1) + rack-openid (1.4.2) rack (>= 1.1.0) ruby-openid (>= 2.1.8) rack-raw-upload (1.1.1) multi_json - rack-ssl (1.3.3) + rack-ssl (1.3.4) rack rack-test (0.6.2) rack (>= 1.0) @@ -134,8 +175,12 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.3.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) + ref (1.0.5) rich (1.4.6) jquery-rails kaminari @@ -146,8 +191,8 @@ GEM sass-rails rmagick (2.13.2) ruby-openid (2.1.8) - rubyzip (1.1.4) - sass (3.2.14) + rubyzip (1.1.6) + sass (3.3.10) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) @@ -163,25 +208,36 @@ GEM shoulda-context (1.2.1) shoulda-matchers (2.6.1) activesupport (>= 3.0.0) + slop (3.5.0) + spork (0.9.2) + spork-testunit (0.0.8) + spork (>= 0.6.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.18.1) + test-unit (2.5.5) + therubyracer (0.12.1) + libv8 (~> 3.16.14.0) + ref + thor (0.19.1) tilt (1.4.1) - treetop (1.4.14) + timers (1.1.0) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) - uglifier (2.4.0) + tzinfo (0.3.40) + uglifier (2.5.1) execjs (>= 0.3.0) json (>= 1.8.0) websocket (1.0.7) + win32console (1.3.2-x86-mingw32) xpath (1.0.0) nokogiri (~> 1.3) PLATFORMS + ruby x86-mingw32 DEPENDENCIES @@ -193,7 +249,11 @@ DEPENDENCIES capybara (~> 2.0.0) coderay (~> 1.0.6) coffee-rails (~> 3.2.1) + factory_girl fastercsv (~> 1.5.0) + guard-rails + guard-spork + guard-test (~> 1.0.0) htmlentities i18n (~> 0.6.0) jquery-rails (~> 2.0.2) @@ -203,6 +263,8 @@ DEPENDENCIES net-ldap (~> 0.3.1) nokogiri (< 1.6.0) paperclip (~> 3.5.4) + pry + pry-nav rack-mini-profiler! rack-openid rails (= 3.2.13) @@ -212,5 +274,6 @@ DEPENDENCIES sass-rails (~> 3.2.3) seems_rateable! shoulda (> 3.3.2) + spork-testunit therubyracer uglifier (>= 1.0.3) diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..75aa93c15 --- /dev/null +++ b/Guardfile @@ -0,0 +1,39 @@ +# More info at https://github.com/guard/guard#readme + +# guard 'rails' do +# watch('Gemfile.lock') +# watch(%r{^(config|lib)/.*}) +# end +# +guard 'spork', :test_unit => true, :test_unit_env => {'RAILS_ENV' => 'test'}, :wait => 60 do + watch('config/application.rb') + watch('config/environment.rb') + watch('config/environments/test.rb') + watch(%r{^config/initializers/.+\.rb$}) + watch('Gemfile.lock') + watch('spec/spec_helper.rb') { :rspec } + watch('test/test_helper.rb') { :test_unit } + watch(%r{features/support/}) { :cucumber } +end + +guard :test, :drb => true, :all_after_pass => false, :all_on_start => false do + watch(%r{^test/.+_test\.rb$}) + watch('test/test_helper.rb') { 'test' } + + # Non-rails + watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } + + # Rails 4 + # watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" } + # watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' } + # watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" } + # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + # watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" } + + # Rails < 4 + watch(%r{^app/models/(.+)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } + watch(%r{^app/controllers/(.+)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)/.+\.erb$}) { |m| "test/functional/#{m[1]}_controller_test.rb" } + watch(%r{^app/views/.+$}) { 'test/integration' } + watch('app/controllers/application_controller.rb') { ['test/functional', 'test/integration'] } +end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 2a3ce15d8..171d34377 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -234,4 +234,103 @@ class AdminController < ApplicationController format.api end end + + #首页定制 + def first_page_made + if request.get? + @first_page = FirstPage.where("page_type = 'project'").first + elsif request.post? + @first_page = FirstPage.where("page_type = 'project'").first + @first_page.web_title = params[:web_title] + @first_page.description = params[:description] + @first_page.title = params[:title] + @first_page.sort_type = params[:sort_type] + if @first_page.save + respond_to do |format| + flash[:notice] = l(:notice_successful_update) + format.html { + redirect_to admin_first_page_made_path + } + format.api { render_api_ok } + #format.json { render json: @first_page, status: :created, location: @first_page } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}" + format.html { + render :action => 'first_page_made' + } + format.api { render_validation_errors(@first_page) } + #format.json { render json: @first_page.errors, status: :unprocessable_entity } + end + end + end + end + + def course_page_made + if request.get? + @course_page = FirstPage.where("page_type = 'course'").first + @first_page = FirstPage.where("page_type = 'project'").first + elsif request.post? + @first_page = FirstPage.where("page_type = 'project'").first + @course_page = FirstPage.where("page_type = 'course'").first + @first_page.web_title = params[:web_title] + @course_page.web_title = params[:web_title] + @course_page.title = params[:course_title] + @course_page.description = params[:course_description] + if @first_page.save && @course_page.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to admin_course_page_made_path + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@course_page.errors.full_messages[0]}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + + render :action => 'course_page_made' + } + format.api { render_validation_errors(@first_page) } + format.api { render_validation_errors(@course_page) } + end + end + end + end + + def contest_page_made + if request.get? + @contest_page = FirstPage.where("page_type = 'contest'").first + @first_page = FirstPage.where("page_type = 'project'").first + elsif request.post? + @first_page = FirstPage.where("page_type = 'project'").first + @contest_page = FirstPage.where("page_type = 'contest'").first + @first_page.web_title = params[:web_title] + @contest_page.web_title = params[:web_title] + @contest_page.title = params[:contest_title] + @contest_page.description = params[:contest_description] + if @first_page.save && @contest_page.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to admin_contest_page_made_path + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@contest_page.errors.full_messages[0]}" + format.html { + render :action => 'contest_page_made' + } + format.api { render_validation_errors(@first_page) } + format.api { render_validation_errors(@contest_page) } + end + end + end + end + end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b283b4792..4964bf6a6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -55,32 +55,35 @@ class AttachmentsController < ApplicationController candown = false if @attachment.container.has_attribute?(:project) && @attachment.container.project project = @attachment.container.project - candown= User.current.member_of?(project) + candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.is_a?(Project) project = @attachment.container - candown= User.current.member_of?(project) + candown= User.current.member_of?(project) || (project.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.has_attribute?(:course) && @attachment.container.course course = @attachment.container.course - candown= User.current.member_of_course?(course) + candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.is_a?(Course) course = @attachment.container - candown= User.current.member_of_course?(course) + candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3 candown = true + else + candown = @attachment.is_public == 1 end if candown || User.current.admin? @attachment.increment_download + + if stale?(:etag => @attachment.digest) + # images are sent inline + send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), + :type => detect_content_type(@attachment), + :disposition => (@attachment.image? ? 'inline' : 'attachment') + end + else render_403 :message => :notice_not_authorized end - - if stale?(:etag => @attachment.digest) - # images are sent inline - send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), - :type => detect_content_type(@attachment), - :disposition => (@attachment.image? ? 'inline' : 'attachment') - end rescue => e redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" end diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 73c1dbd90..fa7eb6052 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -2,7 +2,7 @@ class AvatarController < ApplicationController #before_filter :set_cache_buster - include AvatarHelper + include AvatarHelper def upload # Make sure that API users get used to set this content type @@ -77,6 +77,40 @@ class AvatarController < ApplicationController } end end + + #add by zjc + #删除图片 + def delete_image + @source_type = params[:source_type] + @source_id = params[:source_id] + @source = nil #eval(@source_type).find(@source_id) + c = Object.const_get(@source_type) + if c.respond_to?(:find) + @source = c.find(@source_id) + end + + diskfile=disk_filename(@source_type,@source_id) + unless diskfile.nil? || diskfile == "" + path = File.dirname(diskfile) + if File.directory?(path) && File.exist?(diskfile) + File.delete(diskfile) + end + end + rescue e do + logger.info e.message + end + respond_to do |format| + format.js + format.api { + if saved + render :action => 'upload', :status => :created + else + render_validation_errors(@avatar) + end + } + end + + end private diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index a728ee6e2..ef0be71ac 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -449,7 +449,7 @@ class BidsController < ApplicationController # 显示作业课程 # add by nwb def show_courseEx - if (User.current.logged? && User.current.member_of_course?(@bid.courses.first)) + if (User.current.logged? && (User.current.member_of_course?(@bid.courses.first) || User.current.admin?)) # flash[:notice] = "" @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current)) @@ -482,7 +482,7 @@ class BidsController < ApplicationController #ended end - if @bid.homework_type == 1 + if @bid.homework_type @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 27851e435..e10d6df88 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -217,7 +217,7 @@ class CoursesController < ApplicationController @issue_category ||= IssueCategory.new @member ||= @course.members.new @trackers = Tracker.sorted.all - end + end def create if User.current.user_extensions.identity @@ -239,18 +239,18 @@ class CoursesController < ApplicationController @trackers = Tracker.sorted.all if User.current.user_extensions.identity == 0 - if @course.save + if @course.save #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]) - m.project_id = -1 - course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) - #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) - if params[:course][:is_public] == '1' - course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) - end - @course.members << m - @course.course_infos << course + 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]) + m.project_id = -1 + course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) + #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + if params[:course][:is_public] == '1' + course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) + end + @course.members << m + @course.course_infos << course #end respond_to do |format| format.html { @@ -272,7 +272,7 @@ class CoursesController < ApplicationController format.api { render_validation_errors(@course) } end end - end + end end @@ -630,7 +630,13 @@ class CoursesController < ApplicationController :with_subprojects => false, :author => @author) @activity.scope_select {|t| has["show_#{t}"]} - events = @activity.events(@date_from, @date_to) + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events = @activity.events(@date_from, @date_to) + else + events = @activity.events(@date_from, @date_to, :is_public => 1) + end @offset, @limit = api_offset_and_limit({:limit => 10}) @events_count = events.count @@ -709,4 +715,4 @@ class CoursesController < ApplicationController -end \ No newline at end of file +end diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 464c4a2b8..89bd9dc92 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -23,6 +23,7 @@ class DocumentsController < ApplicationController before_filter :find_model_object, :except => [:index, :new, :create] before_filter :find_project_from_association, :except => [:index, :new, :create] before_filter :authorize , :except => [:index]#Added by young + before_filter :authorize_document helper :attachments @@ -100,4 +101,12 @@ class DocumentsController < ApplicationController end redirect_to document_path(@document) end + + # 权限判断 + # add by nwb + def authorize_document + if !(User.current.admin? || User.current.member_of?(@project) || @document.is_public==1) + render_403 :message => :notice_not_authorized + end + end end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 3b8b4b928..9c41f91d6 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -50,14 +50,14 @@ class ForumsController < ApplicationController def index @offset, @limit = api_offset_and_limit({:limit => 10}) - @forums_all = Forum.all + @forums_all = Forum.where('1=1') @forums_count = @forums_all.count @forums_pages = Paginator.new @forums_count, @limit, params['page'] @offset ||= @forums_pages.offset - # @forums = @forums_all.offset(@offset).limit(@limit).all - @forums = Forum.all + @forums = @forums_all.offset(@offset).limit(@limit).all + #@forums = Forum.all respond_to do |format| format.html # index.html.erb format.json { render json: @forums } diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 2f7d6e600..edff1888b 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -119,6 +119,7 @@ class IssuesController < ApplicationController @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young + @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq respond_to do |format| format.html { @@ -194,6 +195,30 @@ class IssuesController < ApplicationController end if saved + + #修改界面增加跟踪者 + watcherlist = @issue.watcher_users + select_users = [] + if params[:issue] + if params[:issue][:watcher_user_ids] + params[:issue][:watcher_user_ids].each do |user_id| + select_users << User.find(user_id) + end + end + end + select_users.each do |user| + if watcherlist.include? user + else + @issue.add_watcher user + end + end + watcherlist.each do |user| + if select_users.include? user + else + @issue.remove_watcher user + end + end + render_attachment_warning_if_needed(@issue) reply_id = params[:reference_user_id].to_i if reply_id > 0 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b2f521992..af2ce81db 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -478,11 +478,11 @@ class ProjectsController < ApplicationController end end - def create - + def create + @course_tag = params[:project][:project_type] if(@course_tag=="1") - if User.current.user_extensions.identity#.include?(UserExtensions::TEACHER,UserExtensions::DEVELOPER) + 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] @@ -501,11 +501,12 @@ class ProjectsController < ApplicationController @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 @course_tag == '1' if User.current.user_extensions.identity == 0 if@course.save if validate_parent_id && @project.save @@ -516,7 +517,7 @@ class ProjectsController < ApplicationController 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' + 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 @@ -529,7 +530,7 @@ class ProjectsController < ApplicationController 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 @@ -562,10 +563,11 @@ class ProjectsController < ApplicationController end 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? + #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) @@ -575,7 +577,7 @@ class ProjectsController < ApplicationController end @project.members << m @project.project_infos << project - end + #end respond_to do |format| format.html { flash[:notice] = l(:notice_successful_create) @@ -583,7 +585,7 @@ class ProjectsController < ApplicationController 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 @@ -685,8 +687,14 @@ class ProjectsController < ApplicationController @activity.scope_select {|t| !has["show_#{t}"].nil?} # logger.debug "=========================================#{@activity.scope}" # @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? - #Added by young - events = @activity.events(@date_from, @date_to) + + # modify by nwb + # 添加私密性判断 + if User.current.member_of?(@project)|| User.current.admin? + events = @activity.events(@date_from, @date_to) + else + events = @activity.events(@date_from, @date_to, :is_public => 1) + end @offset, @limit = api_offset_and_limit({:limit => 10}) @events_count = events.count @@ -826,6 +834,7 @@ class ProjectsController < ApplicationController def update @project.safe_attributes = params[:project] + @project.dts_test = params[:project][:dts_test] if validate_parent_id && @project.save @course = Course.find_by_extra(@project.identifier) unless @course.nil? diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b86630d98..7588eef21 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -92,57 +92,74 @@ class RepositoriesController < ApplicationController end def create - ##xianbo - @root_path=RepositoriesHelper::ROOT_PATH - @repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git" - @project_path=@root_path+"htdocs/"+@repository_name - @repository_tag=params[:repository][:upassword] - @repo_name=User.current.login.to_s+"_"+params[:repository][:identifier] - logger.info "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+": "+@repository_tag - logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name - attrs = pickup_extra_info - if((@repository_tag!="")&¶ms[:repository_scm]=="Git") + if params[:repository_scm].to_s == 'Gitlab' + # add by nwb + # 增加对gitlab版本库的支持 + attrs = pickup_extra_info + @repository = Repository.factory('Git') + @repository.safe_attributes = params[:repository] + if attrs[:attrs_extra].keys.any? + @repository.merge_extra_info(attrs[:attrs_extra]) + end + @repository.project = @project + if request.post? && @repository.save + redirect_to settings_project_path(@project, :tab => 'repositories') + else + render :action => 'new' + end + else # 原逻辑 + ##xianbo + @root_path=RepositoriesHelper::ROOT_PATH + @repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git" + @project_path=@root_path+"htdocs/"+@repository_name + @repository_tag=params[:repository][:upassword] + @repo_name=User.current.login.to_s+"_"+params[:repository][:identifier] + logger.info "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+": "+@repository_tag + logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name + attrs = pickup_extra_info + if((@repository_tag!="")&¶ms[:repository_scm]=="Git") params[:repository][:url]=@project_path - end - ###xianbo - @repository = Repository.factory(params[:repository_scm]) - @repository.safe_attributes = params[:repository] - if attrs[:attrs_extra].keys.any? - @repository.merge_extra_info(attrs[:attrs_extra]) - end - #by xianbo - - @repository.project = @project - if request.post? && @repository.save - if(params[:repository_scm]=="Git") - system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag - system "echo -e '"+@repo_name+"-write:"+ - " "+@repo_name+"' >> "+@root_path+"group.passwd" - system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s - system "git init --bare "+@project_path - system "mv "+@project_path+"/hooks/post-update{.sample,}" - system "chmod a+x "+@project_path+"/hooks/post-update" - system "echo -e 'Allow from all \n Order Deny,Allow \n "+ - " \n"+ - "Require group "+@repo_name+"-write \n "+ - " \n ' >> "+ - @root_path+"htdocs/"+ @repository_name+"/.htaccess" - system "cd "+@project_path+" ;git update-server-info" - # if(create_repo_file&&create_passwd&&create_group&&init_repository&&add_privilege&&init_server_info) - # else - # logger.info "An error occured when authenticating "+"create passwd"+@creat_passwd+"create_group"+ - # crate_group+"create repository file "+create_repo_file+"init repository"+init_repostory+ - # "aad privilege to rpository"+add_privilege+"init server infos"+init_server_info - # end + end + ###xianbo + @repository = Repository.factory(params[:repository_scm]) + @repository.safe_attributes = params[:repository] + if attrs[:attrs_extra].keys.any? + @repository.merge_extra_info(attrs[:attrs_extra]) + end + #by xianbo + + @repository.project = @project + if request.post? && @repository.save + if(params[:repository_scm]=="Git") + system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag + system "echo -e '"+@repo_name+"-write:"+ + " "+@repo_name+"' >> "+@root_path+"group.passwd" + system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s + system "git init --bare "+@project_path + system "mv "+@project_path+"/hooks/post-update{.sample,}" + system "chmod a+x "+@project_path+"/hooks/post-update" + system "echo -e 'Allow from all \n Order Deny,Allow \n "+ + " \n"+ + "Require group "+@repo_name+"-write \n "+ + " \n ' >> "+ + @root_path+"htdocs/"+ @repository_name+"/.htaccess" + system "cd "+@project_path+" ;git update-server-info" + # if(create_repo_file&&create_passwd&&create_group&&init_repository&&add_privilege&&init_server_info) + # else + # logger.info "An error occured when authenticating "+"create passwd"+@creat_passwd+"create_group"+ + # crate_group+"create repository file "+create_repo_file+"init repository"+init_repostory+ + # "aad privilege to rpository"+add_privilege+"init server infos"+init_server_info + # end @repository.update_attributes(:login => User.current.login.to_s) - end - redirect_to settings_project_path(@project, :tab => 'repositories') - else if(@repository_tag) - render :action => 'newrepo', :layout =>'base_projects' - else - render :action => 'new', :layout =>'base_projects' + end + redirect_to settings_project_path(@project, :tab => 'repositories') + else if(@repository_tag) + render :action => 'newrepo', :layout =>'base_projects' + else + render :action => 'new', :layout =>'base_projects' + end + end end - end end def edit diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index f34e72402..ae9336161 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -38,7 +38,7 @@ class StoresController < ApplicationController LIMIT = 12 unless const_defined?(:LIMIT) def index @projects_attach = project_classification(0).take(LIMIT) - @courses_attach = Attachment.includes(:course).where("courses.is_public = ?", 1). + @courses_attach = Attachment.includes(:course).where("courses.is_public = 1"). where(container_type: 'Course'). limit(LIMIT) # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3d512b5d..e81355260 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -53,6 +53,7 @@ class UsersController < ApplicationController include CustomFieldsHelper include AvatarHelper include WordsHelper + include GitlabHelper # added by liuping 关注 @@ -329,7 +330,7 @@ class UsersController < ApplicationController when 'xml', 'json' @offset, @limit = api_offset_and_limit({:limit => 15}) else - @limit = 15#per_page_option + @limit = 15#per_page_option end @status = params[:status] || 1 diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index bf18332df..6a1772c8b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -16,11 +16,44 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class WelcomeController < ApplicationController + include ApplicationHelper + include WelcomeHelper caches_action :robots # before_filter :fake, :only => [:index, :course] before_filter :entry_select, :only => [:index] def index + @first_page = FirstPage.where("page_type = 'project'").first + @hot_projects = find_miracle_project(10, 3) + @hot_projects_ids = [] + @hot_projects.each do |p| + @hot_projects_ids << p + end + @projects_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + where("#{Project.table_name}.project_type = ? and #{Project.table_name}.id in (?)", Project::ProjectType_project,@hot_projects_ids) + if @first_page.nil? || @first_page.sort_type.nil? + @projects = @projects_all.order("grade desc") + else + case @first_page.sort_type + when 0 + @projects = @projects_all.order("created_on desc") + when 1 + @projects = @projects_all.order("grade desc") + when 2 + @projects = @projects_all.order("watchers_count desc") + + #gcm + #when '3' + #@projects=desc_sort_course_by_avtivity(@project_activity_count_array,@project_all_array) + # @projects=handle_project @projects_all,@project_activity_count + # @s_type = 3 + # @projects = @projects[@project_pages.offset, @project_pages.per_page] + + else + @projects = @projects_all.order("grade desc") + end + end end @@ -30,6 +63,7 @@ class WelcomeController < ApplicationController end def course + @course_page = FirstPage.where("page_type = 'course'").first if params[:school_id] @school_id = params[:school_id] elsif User.current.logged? && User.current.user_extensions.school @@ -41,13 +75,24 @@ class WelcomeController < ApplicationController def logolink() + @course_page = FirstPage.where("page_type = 'course'").first + logo = get_avatar?(@course_page) id = params[:school_id] logo_link = "" - if id.nil? and User.current.user_extensions.school.nil? - logo_link = '/images/transparent.png' + if id.nil? && User.current.user_extensions.school.nil? + if logo + logo_link = url_to_avatar(@course_page) + else + logo_link = '/images/transparent.png' + end + else if id == "0" - logo_link = '/images/transparent.png' + if logo + logo_link = url_to_avatar(@course_page) + else + logo_link = '/images/transparent.png' + end else if id.nil? if School.find(User.current.user_extensions.school.id).logo_link.nil? @@ -66,7 +111,7 @@ class WelcomeController < ApplicationController def contest - + @contest_page = FirstPage.where("page_type = 'contest'").first end def search diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6bbf6ed6..bf125972b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -80,11 +80,12 @@ module ApplicationHelper name = h(user.name(options[:format])) end - if user.active? || (User.current.admin? && user.logged?) - link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes - else - name - end + #if user.active? || (User.current.admin? && user.logged?) + # link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes + #else + # name + #end + link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes else h(user.to_s) end @@ -256,8 +257,8 @@ module ApplicationHelper end def format_activity_description(text) - h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...') - ).gsub(/[\r\n]+/, "
").html_safe + h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "
").html_safe + #h(truncate(text.to_s, :length => 120).gsub(/<\/?.*?>/,"")).html_safe end def format_version_name(version) @@ -625,10 +626,15 @@ module ApplicationHelper end def html_title(*args) + first_page = FirstPage.where("page_type = 'project'").first if args.empty? title = @html_title || [] title << @project.name if @project - title << Setting.app_title unless Setting.app_title == title.last + if first_page.nil? || first_page.web_title.nil? + title << Setting.app_title unless Setting.app_title == title.last + else + title << first_page.web_title unless first_page.web_title == title.last + end title.select {|t| !t.blank? }.join(' - ') else @html_title ||= [] diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index 2ebdae0c8..3f6802f59 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -38,7 +38,7 @@ module AvatarHelper avatar_image(source) else File.join(relative_path,avatar_directory(source.class),'0') - end + end end def get_avatar?(source) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b4b89bb0f..b03f6cfa1 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -104,10 +104,17 @@ module CoursesHelper garble count end - alias studentCountOrigin studentCount + # 注意:此方法有问题,速度慢且结果不准 + # alias studentCountOrigin studentCount + #def studentCount course + # count = studentCountOrigin course + #garble count + # end + + # 学生人数计算 + # add by nwb def studentCount course - count = studentCountOrigin course - garble count + course.student.count end def eventToLanguageCourse event_type, course diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb new file mode 100644 index 000000000..ceaaf6d21 --- /dev/null +++ b/app/helpers/gitlab_helper.rb @@ -0,0 +1,247 @@ +# Gitlab5.3 API操作接口 +# Add by nwb +# 暂时没支持SSH +# 接口通过HTTP协议与服务器交互,理论上只要能安装gitlab的操作系统本接口都能支持 +# 本机的测试环境是Ubuntu 12.04 + +module GitlabHelper + + # gitlab版本库数据本地保存的根目录 + ROOT_PATH="/home/git/repositories/" + PROJECT_PATH_CUT = 40 + # gitlab版本库所在服务器 + # 注意REPO_IP_ADDRESS必须以http://开头,暂时只支持HTTP协议,未支持SSH + #REPO_IP_ADDRESS = "http://" + Setting.repository_domain + REPO_IP_ADDRESS = "http://192.168.137.100" + GITLAB_API = "/api/v3" + + # 用户在项目中的权限级别 + GUEST = 10 + REPORTER = 20 + DEVELOPER = 30 + MASTER = 40 + + # gitlab的登录验证信息 + # add by nwb + def self.gitlab_token=(token) + Thread.current[:gitlab_token] = token + end + + # gitlab的登录验证信息 + # add by nwb + def self.gitlab_token + Thread.current[:gitlab_token] ||= nil + end + + # 登录gitlab + # add by nwb + def login_gitlab(email,password) + url = REPO_IP_ADDRESS + GITLAB_API + "/session" + uri = URI.parse(url) + data = {email:email, password:password} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + GitlabHelper.gitlab_token= temp['private_token'] + return true + else + return false + end + rescue =>err + return false + end + end + + # 创建项目 + # add by nwb + def create_project(project_name) + url = REPO_IP_ADDRESS + GITLAB_API + "/projects" + uri = URI.parse(url) + data = {name:project_name, private_token:GitlabHelper.gitlab_token} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + #新创建项目的版本库地址 + respo = temp['http_url_to_repo'] + respo['http://localhost'] = REPO_IP_ADDRESS + # 新创建项目的web地址 + webaddress = temp['web_url'] + webaddress['http://localhost'] = REPO_IP_ADDRESS + return true + else + return false + end + rescue =>err + return false + end + end + + # 为指定用户创建版本库 + # project_name:版本库名称 user_id:Gitlab版本库中的用户编号 + # add by nwb + def create_project_for_user(project_name,user_id) + url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id + uri = URI.parse(url) + data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + #新创建项目的版本库地址 + respo = temp['http_url_to_repo'] + respo['http://localhost'] = REPO_IP_ADDRESS + # 新创建项目的web地址 + webaddress = temp['web_url'] + webaddress['http://localhost'] = REPO_IP_ADDRESS + return true + else + return false + end + rescue =>err + return false + end + end + + # 创建用户 + # loginname:登录名称(版本库路径包含) name:用户姓名 + # add by nwb + def create_user (loginname,name,password,email) + url = REPO_IP_ADDRESS + GITLAB_API + "/users" + uri = URI.parse(url) + data = {email:email,password:password,username:loginname, name:name, private_token:GitlabHelper.gitlab_token} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + #新创建的gitlab用户编号(需保存) + user_id = temp['id'] + return true + else + return false + end + rescue =>err + return false + end + end + + # 删除用户 + # user_id:用户在gitlab中的id + # add by nwb + def delete_user(user_id) + url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id + uri = URI.parse(url) + data = {id:user_id,private_token:GitlabHelper.gitlab_token} + http = Net::HTTP.new uri.host, uri.port + begin + req = Net::HTTP::Delete.new(uri.request_uri) + req.form_data = data + res= http.start { |http| http.request req } + if res.code == '200' + temp = ActiveSupport::JSON.decode(res.body) + # 删除成功,对应更新trustie用户的gitlab用户编号 + return true + else + return false + end + rescue =>err + return false + end + end + + # 给用户添加一个可操作的项目 + # 若用户已在该项目中,权限级别取新权限与现有权限的最大值 + # project_id:项目在gitlab中的id user_id:用户在gitlab中的id + # access_level为用户在项目中的权限级别,对应如下: + #GUEST = 10 + #REPORTER = 20 + #DEVELOPER = 30 + #MASTER = 40 + # add by nwb + def add_user_to_project(project_id,user_id,access_level) + url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members" + uri = URI.parse(url) + data = {id:project_id,user_id:user_id,access_level:access_level, private_token:GitlabHelper.gitlab_token} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + return true + else + return false + end + rescue =>err + return false + end + end + + # 从项目中删除用户 + # project_id:项目在gitlab中的ids user_id:用户在gitlab中的id + # add by nwb + def delete_user_from_project(project_id,user_id) + url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members/" + user_id + uri = URI.parse(url) + data = {id:project_id,user_id:user_id,private_token:GitlabHelper.gitlab_token} + http = Net::HTTP.new uri.host, uri.port + begin + req = Net::HTTP::Delete.new(uri.request_uri) + req.form_data = data + res= http.start { |http| http.request req } + if res.code == '200' + temp = ActiveSupport::JSON.decode(res.body) + return true + else + return false + end + rescue =>err + return false + end + end + + # 发送post消息 + # add by nwb + def post(url, params) + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + end + begin + request = Net::HTTP::Post.new(uri.request_uri) + request['Content-Type'] = 'application/json;charset=utf-8' + request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0' + request['X-ACL-TOKEN'] = 'xxx_token' + #request.set_form_data(params) + request.body = params.to_json + response = http.start { |http| http.request(request) } + return JSON.parse response.body + rescue =>err + return nil + end + end + + # 发送get消息 + # add by nwb + def get(url, params) + uri = URI.parse(url) + uri.query = URI.encode_www_form(params) + http = Net::HTTP.new uri.host, uri.port + if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + end + begin + request = Net::HTTP::Get.new uri.request_uri + request['Content-Type'] = 'application/json;charset=utf-8' + request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0' + request['X-ACL-TOKEN'] = 'xxx_token' + response = http.start { |http| http.request request } + return JSON.parse response.body + rescue =>err + return nil + end + end + +end \ No newline at end of file diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index 0c7fdac43..b4cd47eb1 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -16,6 +16,8 @@ module StoresHelper news_path(container) when 'Project' project_files_path(container) + when 'Course' + course_files_path(container) when 'Version' # version_path(container) project_files_path(container.project) diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 4ff5a48e4..99357a3d0 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -208,7 +208,7 @@ module WelcomeHelper #c1 = find_new_project(sum).to_a.dup #c2 = find_all_hot_project(sum).to_a.dup #(c2.take(sum-max)+c1.take(max)).take(sum) - find_all_hot_project(sum).to_a.dup + find_all_hot_project(sum).dup#.to_a.dup end def find_new_course limit=15 @@ -433,7 +433,7 @@ module WelcomeHelper # FROM projects AS p LEFT OUTER JOIN ( # SELECT project_id,grade FROM project_statuses # WHERE project_type = #{project_type} ORDER BY #{order_by} LIMIT #{limit} ) AS t ON p.id = t.project_id ") - Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit).all + Project.visible.joins(:project_status).where("#{Project.table_name}.project_type = ?", project_type).order(order_by).limit(limit)#.all end def sort_bid_by_hot_rails reward_type, limit = 10 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 0eb3e7666..b301ba73c 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -39,19 +39,22 @@ class Attachment < ActiveRecord::Base #课程资源文件 acts_as_activity_provider :type => 'course_files', + :is_public => 'attachments.is_public', :permission => :view_files, :author_key => :author_id, :find_options => {:select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Course.table_name} ON ( #{Attachment.table_name}.container_type='Course' AND #{Attachment.table_name}.container_id = #{Course.table_name}.id )"} acts_as_activity_provider :type => 'files', + :is_public => 'attachments.is_public', :permission => :view_files, :author_key => :author_id, - :find_options => {:select => "#{Attachment.table_name}.*", + :find_options => { :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )"} acts_as_activity_provider :type => 'documents', + :is_public => 'documents.is_public', :permission => :view_documents, :author_key => :author_id, :find_options => {:select => "#{Attachment.table_name}.*", diff --git a/app/models/course.rb b/app/models/course.rb index b6974eed0..75bac905c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -21,7 +21,7 @@ class Course < ActiveRecord::Base has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy - has_many :student, :through => :students_for_courses, :source => :user + has_many :student, :class_name => 'StudentsForCourse', :source => :user has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy has_many :enabled_modules, :dependent => :delete_all has_many :boards, :dependent => :destroy, :order => "position ASC" @@ -39,7 +39,7 @@ class Course < ActiveRecord::Base validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/ before_save :self_validate - after_save :create_board_sync + after_create :create_board_sync before_destroy :delete_all_members safe_attributes 'extra', @@ -104,7 +104,24 @@ class Course < ActiveRecord::Base # 课程的短描述信息 def short_description(length = 255) - description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + description.gsub(/<\/?.*?>/,"").html_safe if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + end + + # 课程的短名称信息 + def short_name(length = 8) + name.gsub(/<\/?.*?>/,"").html_safe if name + end + + def strip_html(html) + return html if html.empty? || !html.include?('<') + output = "" + tokenizer = HTML::Tokenizer.new(html) + while token = tokenizer.next + node = HTML::Node.parse(nil, 0, 0, token, false) + output += token unless (node.kind_of? HTML::Tag) or (token =~ /^ Proc.new {|o| "#{l(:label_document)}: #{o.title}"}, :author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) }, :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}} - acts_as_activity_provider :find_options => {:include => :project} + acts_as_activity_provider :find_options => {:include => :project}, + :is_public => 'documents.is_public' validates_presence_of :project, :title, :category validates_length_of :title, :maximum => 60 @@ -39,7 +40,7 @@ class Document < ActiveRecord::Base includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args)) } - safe_attributes 'category_id', 'title', 'description' + safe_attributes 'category_id', 'title', 'description','is_public' def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_documents, project) diff --git a/app/models/first_page.rb b/app/models/first_page.rb new file mode 100644 index 000000000..52c6e204d --- /dev/null +++ b/app/models/first_page.rb @@ -0,0 +1,6 @@ +class FirstPage < ActiveRecord::Base + attr_accessible :description, :title, :web_title,:page_type,:sort_type + validates_presence_of :web_title, :title, :description,:page_type + validates_length_of :web_title,:title, maximum: 30 + validates_length_of :description, maximum: 100 +end diff --git a/app/models/issue.rb b/app/models/issue.rb index 550e0dc5d..4c5e77cb5 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -562,6 +562,14 @@ class Issue < ActiveRecord::Base @workflow_rule_by_attribute = result if user.nil? result end + # 缺陷的短描述信息 + def short_description(length = 255) + # 不再使用短描述 + #description.gsub(/<\/?.*?>/,"").html_safe if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + description + end + private :workflow_rule_by_attribute def done_ratio @@ -1513,4 +1521,6 @@ class Issue < ActiveRecord::Base def be_user_score_new_issue UserScore.project(:post_issue, User.current,self, { issue_id: self.id }) end + + end diff --git a/app/models/news.rb b/app/models/news.rb index 9a0f8b75c..860dd0baa 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -74,6 +74,14 @@ class News < ActiveRecord::Base visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all end + # 新闻的短描述信息 + def short_description(length = 255) + #description.gsub(/<\/?.*?>/,"").html_safe if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + # 不再使用短描述 + description + end + private def add_author_as_watcher diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index e3556ce55..4a657edb4 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -84,7 +84,10 @@ class OpenSourceProject < ActiveRecord::Base # end def short_description(length = 255) - description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + #description.gsub(/<\/?.*?>/,"").html_safe if description + # 不再使用短描述 + description end def applied_by?(user) diff --git a/app/models/project.rb b/app/models/project.rb index 37ca8f20b..6c453baa9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -41,7 +41,7 @@ class Project < ActiveRecord::Base has_many :principals, :through => :member_principals, :source => :principal has_many :enabled_modules, :dependent => :delete_all has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" - has_many :issues, :dependent => :destroy, :include => [:status, :tracker] , :order => "id ASC" + has_many :issues, :dependent => :destroy, :include => [:status, :tracker] has_many :issue_changes, :through => :issues, :source => :journals has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" has_many :time_entries, :dependent => :delete_all @@ -127,7 +127,7 @@ class Project < ActiveRecord::Base after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_save :create_board_sync + after_create :create_board_sync before_destroy :delete_all_members def remove_references_before_destroy return if self.id.nil? @@ -156,7 +156,7 @@ class Project < ActiveRecord::Base where(nil) else pattern = "%#{arg.to_s.strip.downcase}%" - where("LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p ", :p => pattern) + where("LOWER(name) LIKE :p ", :p => pattern) end } scope :project_entities, -> { where(project_type: ProjectType_project) } @@ -629,7 +629,10 @@ class Project < ActiveRecord::Base # Returns a short description of the projects (first lines) def short_description(length = 255) - description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + # 不再使用短描述 + # description.gsub(/<\/?.*?>/,"").html_safe if description + description end def css_classes diff --git a/app/models/setting.rb b/app/models/setting.rb index 583d034df..3f11ef7c2 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -163,7 +163,7 @@ class Setting < ActiveRecord::Base end # fixed domain url in development. tantantan's bug - if Rails.env.development? + if Rails.env.development? || Rails.env.test? methods.map do |m| define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/ end diff --git a/app/models/user.rb b/app/models/user.rb index 9665a4fb0..195346e7c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -996,4 +996,4 @@ class AnonymousUser < User def destroy false end -end \ No newline at end of file +end diff --git a/app/views/admin/contest_page_made.html.erb b/app/views/admin/contest_page_made.html.erb new file mode 100644 index 000000000..a4407cd6b --- /dev/null +++ b/app/views/admin/contest_page_made.html.erb @@ -0,0 +1,39 @@ +

<%=l(:label_first_page_made)%>

+ +<%= form_tag(:controller => 'admin', :action => 'contest_page_made') do %> +

+ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+
+ +
+ +

<%=l(:label_contest_first_page)%>

+

+ +

+
+ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@contest_page} %> +
+

+ + <%= text_field_tag 'contest_title', params[:label_site_title], :value => @contest_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+ +

+ + <%= text_area_tag 'contest_description',@contest_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +
+ + + +
\ No newline at end of file diff --git a/app/views/admin/course_page_made.html.erb b/app/views/admin/course_page_made.html.erb new file mode 100644 index 000000000..7d73c7c6e --- /dev/null +++ b/app/views/admin/course_page_made.html.erb @@ -0,0 +1,37 @@ +

<%=l(:label_first_page_made)%>

+ +<%= form_tag(:controller => 'admin', :action => 'course_page_made') do %> +

+ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+
+ +
+

<%=l(:label_course_first_page)%>

+

+ +

+
+ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@course_page} %> +
+

+ + <%= text_field_tag 'course_title', params[:label_site_title], :value => @course_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ + <%= text_area_tag 'course_description',@course_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +
+ + + +
\ No newline at end of file diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb new file mode 100644 index 000000000..242b7c689 --- /dev/null +++ b/app/views/admin/first_page_made.html.erb @@ -0,0 +1,46 @@ +

<%=l(:label_first_page_made)%>

+ +<%= form_tag(:controller => 'admin', :action => 'first_page_made') do %> +

+ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+
+ +
+

<%=l(:label_project_first_page)%>

+

+ +

+
+ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %> +
+ +

+ + <%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ + <%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ + +

+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +
+ + + +
\ No newline at end of file diff --git a/app/views/admin/project_page_made.html.erb b/app/views/admin/project_page_made.html.erb new file mode 100644 index 000000000..e338c21a9 --- /dev/null +++ b/app/views/admin/project_page_made.html.erb @@ -0,0 +1,31 @@ +

<%=l(:label_first_page_made)%>

+ +<%= form_tag(:controller => 'admin', :action => 'first_page_made') do %> +

+ + <%= text_field_tag 'web_title', params[:wbe_title],:value => @first_page.web_title, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

<%=l(:label_project_first_page)%>

+

+ +

+
+ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %> +
+ +

+ + <%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+

+ + <%= text_area_tag 'description',@first_page.description,:rows => 8, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

+ + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> +
+ + + +
\ No newline at end of file diff --git a/app/views/avatar/_avatar_form.html.erb b/app/views/avatar/_avatar_form.html.erb index 272397c62..6f9b9c7b1 100644 --- a/app/views/avatar/_avatar_form.html.erb +++ b/app/views/avatar/_avatar_form.html.erb @@ -1,3 +1,4 @@ +
"):d.push('');return d.join("")},htmlEncode:function(b){return(""+b).replace(/&/g,"&").replace(/>/g,">").replace(//g,">")},htmlDecodeAttr:function(b){return b.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">")},getNextNumber:function(){var b=0;return function(){return++b}}(),getNextId:function(){return"cke_"+this.getNextNumber()},override:function(b,a){var d=a(b);d.prototype=b.prototype;return d},setTimeout:function(b,a,d,g,e){e||(e=window);d||(d=e);return e.setTimeout(function(){g?b.apply(d,[].concat(g)): -b.apply(d)},a||0)},trim:function(){var b=/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g;return function(a){return a.replace(b,"")}}(),ltrim:function(){var b=/^[ \t\n\r]+/g;return function(a){return a.replace(b,"")}}(),rtrim:function(){var b=/[ \t\n\r]+$/g;return function(a){return a.replace(b,"")}}(),indexOf:function(b,a){if(typeof a=="function")for(var d=0,g=b.length;d=0?b[d]:null},bind:function(b,a){return function(){return b.apply(a,arguments)}},createClass:function(b){var a=b.$,d=b.base,g=b.privates||b._,e=b.proto,b=b.statics;!a&&(a=function(){d&&this.base.apply(this,arguments)});if(g)var m=a,a=function(){var d=this._||(this._={}),a;for(a in g){var b=g[a];d[a]=typeof b=="function"?CKEDITOR.tools.bind(b,this):b}m.apply(this,arguments)};if(d){a.prototype=this.prototypedCopy(d.prototype);a.prototype.constructor=a;a.base= -d;a.baseProto=d.prototype;a.prototype.base=function(){this.base=d.prototype.base;d.apply(this,arguments);this.base=arguments.callee}}e&&this.extend(a.prototype,e,true);b&&this.extend(a,b,true);return a},addFunction:function(b,c){return a.push(function(){return b.apply(c||this,arguments)})-1},removeFunction:function(b){a[b]=null},callFunction:function(b){var c=a[b];return c&&c.apply(window,Array.prototype.slice.call(arguments,1))},cssLength:function(){var a=/^-?\d+\.?\d*px$/,c;return function(d){c= -CKEDITOR.tools.trim(d+"")+"px";return a.test(c)?c:d||""}}(),convertToPx:function(){var a;return function(c){if(!a){a=CKEDITOR.dom.element.createFromHtml('
',CKEDITOR.document);CKEDITOR.document.getBody().append(a)}if(!/%$/.test(c)){a.setStyle("width",c);return a.$.clientWidth}return c}}(),repeat:function(a,c){return Array(c+1).join(a)},tryThese:function(){for(var a,c=0,d=arguments.length;c8)&&e)a=e+":"+a;return new CKEDITOR.dom.nodeList(this.$.getElementsByTagName(a))},getHead:function(){var a=this.$.getElementsByTagName("head")[0];return a= -a?new CKEDITOR.dom.element(a):this.getDocumentElement().append(new CKEDITOR.dom.element("head"),true)},getBody:function(){return new CKEDITOR.dom.element(this.$.body)},getDocumentElement:function(){return new CKEDITOR.dom.element(this.$.documentElement)},getWindow:function(){return new CKEDITOR.dom.window(this.$.parentWindow||this.$.defaultView)},write:function(a){this.$.open("text/html","replace");CKEDITOR.env.ie&&(a=a.replace(/(?:^\s*]*?>)|^/i,'$&\n