diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100644 index 000000000..f891d6b75 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,31 @@ +app/models/setting.rb :165 + # fixed domain url in development. tantantan's bug + if Rails.env.development? + methods.map do |m| + define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/ + end + end + 程序部分链接中制定了subdomain参数,使链接在二级域名中来回跳转。 + 为了开发方便,使之功能在development模式下失效。 + # => nyan +================================================================================ +app/controller/projects_controller.rb ===> projects#fake + fake filter: 修改了传到页面中的Count后缀的数量 + 改为正确的数量,删掉fake过滤器即可 +================================================================================ +#导航栏匹配域名显示和改变 +app\helper\application_helper.rb +# rewrite navigation + +app\views\layouts\_base_header.html.erb +# reset navigation by domain name and url through regular match +================================================================================ +#首页根据域名匹配进入不同的页面 +app\controller\welcome_controller.rb + def entry_select_user + if request.original_url.match(/user\.trustie\.net/) + redirect_to(:controller => "users", :action => "index") + return 0 + end + end +================================================================================ \ No newline at end of file diff --git a/ReadMe鎺ユ墜蹇呰.txt b/ReadMe鎺ユ墜蹇呰.txt deleted file mode 100644 index d7c1aa009..000000000 --- a/ReadMe鎺ユ墜蹇呰.txt +++ /dev/null @@ -1,11 +0,0 @@ -app\models\setting.rb :165 - # fixed domain url in development. tantantan's bug - if Rails.env.development? - methods.map do |m| - define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/ - end - end - 程序部分链接中制定了subdomain参数,使链接在二级域名中来回跳转。 - 为了开发方便,使之功能在development模式下失效。 - # => nyan -================================================================================ diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index f10e84cc0..769214d65 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -37,15 +37,11 @@ class AccountController < ApplicationController end # Log out current user and redirect to welcome page - # cookies[:login_flag] 鏄负浜嗛厤鍚堟瘺xx - # 閫鍑哄啀鐧诲綍鐨勮瘽鐩存帴璺宠浆鍒扮敤鎴烽椤佃屼笉鏄櫥闄嗗墠鐨勯〉闈 - # 鐩稿簲澶勭悊鏂规硶鍦╝pplication_helper#is_logout? :1106 def logout if User.current.anonymous? redirect_to home_url elsif request.post? logout_user - cookies[:login_flag] = 1 redirect_to home_url end # display the logout form diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 51b7fa804..a25b346ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -353,14 +353,13 @@ class ApplicationController < ActionController::Base url end - def redirect_back_or_default(default) + def redirect_back_or_default(default, options={}) back_url = params[:back_url].to_s if back_url.present? begin uri = URI.parse(back_url) # do not redirect user to another host or to the login or register page - #by young - if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) && (uri.path!='/') + if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) redirect_to(back_url) return end @@ -368,6 +367,9 @@ class ApplicationController < ActionController::Base logger.warn("Could not redirect to invalid URL #{back_url}") # redirect to default end + elsif options[:referer] + redirect_to_referer_or default + return end redirect_to default false diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 01d2ea890..1c02326a7 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -20,6 +20,8 @@ class AttachmentsController < ApplicationController before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young before_filter :delete_authorize, :only => :destroy before_filter :authorize_global, :only => :upload + + before_filter :require_login, only: [:download] accept_api_auth :show, :download, :upload diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 32878a2cd..2b0ed762c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -20,6 +20,17 @@ class BidsController < ApplicationController include ApplicationHelper helper :projects helper :words + helper :welcome + + def homework_ajax_modal + @bid = Bid.find_by_id(params[:id]) + # find_bid + respond_to do |format| + format.js + end + end + + def index @project_type = params[:project_type] # Modified by nie @@ -735,12 +746,12 @@ class BidsController < ApplicationController @homework.save_attachments(params[:attachments]) render_attachment_warning_if_needed(@homework) - - if @homework.save - @homework_flag = l(:label_bidding_homework_succeed) - else - @homework_flag = l(:label_bidding_homework_failed) - end + + @homework_flag = if @homework.save + l(:label_bidding_homework_succeed) + else + l(:label_bidding_homework_failed) + end if @homework.attachments.empty? @homework.delete @@ -754,7 +765,9 @@ class BidsController < ApplicationController @homework_list = @bid.homeworks respond_to do |format| format.html{ - redirect_to project_for_bid_path, notice: @homework_flag.to_s + #redirect_to project_for_bid_path, notice: @homework_flag.to_s + flash[:notice] = @homework_flag.to_s + redirect_back_or_default(project_for_bid_path) } format.js end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d3481e2ae..abe9e3291 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -218,8 +218,10 @@ class ProjectsController < ApplicationController def search #modified by nie - @projects = Project.visible - @projects = @projects.visible.where('project_type = ?', params[:project_type]).like(params[:name]) if params[:name].present? + project_type = params[:project_type] + projects_all = (project_type.eql? Project::ProjectType_project) ? Project.project_entities : Project.course_entities + @projects = projects_all.visible + @projects = @projects.visible.like(params[:name]) if params[:name].present? @offset, @limit = api_offset_and_limit({:limit => 10}) @project_count = @projects.visible.count @project_pages = Paginator.new @project_count, @limit, params['page'] @@ -346,7 +348,7 @@ class ProjectsController < ApplicationController end def new - @project_type = params[:project_type] + @project_type = params[:project_type] ||= params[:course] @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @@ -360,9 +362,9 @@ class ProjectsController < ApplicationController @course_tag = params[:course] @course = Course.new @course.safe_attributes = params[:course] - else - render_404 - return -1 + else # default Project + @project = Project.new + @project.safe_attributes = params[:project] end render :layout => 'base' end @@ -849,8 +851,7 @@ class ProjectsController < ApplicationController def select_project_layout project = Project.find_by_id(params[:id]) - project ||= @project - project ||= @course + project ||= @project ||= @course ||= params[:course] ||= params[:project_type] (project.try(:project_type) == Project::ProjectType_project) ? 'base_projects' : 'base_courses' end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 3a7e0f635..0d6331260 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -144,7 +144,6 @@ class TagsController < ApplicationController @taggable_type = numbers_to_object_type(params[:taggable_type]) @obj = get_object(@taggable_id,params[:taggable_type]) - logger.debug "==========================================#{@obj}" @object_flag = params[:taggable_type] # if can_remove_tag?(User.current,@taggable_id,@taggable_type) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 904920c5a..31168595e 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -17,56 +17,16 @@ class WelcomeController < ApplicationController caches_action :robots + before_filter :fake, :only => [:index, :course] before_filter :entry_select_course, :entry_select_contest, :entry_select_user, :only => [:index] def index - # @news = News.latest User.current - # @projects = Project.latest User.current - #by young - (redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration] - if request.get? - session[:auth_source_registration] = nil - @user = User.new(:language => current_language.to_s) - else - user_params = params[:user] || {} - @user = User.new - @user.safe_attributes = user_params - @user.admin = false - @user.register - if session[:auth_source_registration] - @user.activate - @user.login = session[:auth_source_registration][:login] - @user.auth_source_id = session[:auth_source_registration][:auth_source_id] - if @user.save - session[:auth_source_registration] = nil - self.logged_user = @user - flash[:notice] = l(:notice_account_activated) - redirect_to my_account_path - end - else - @user.login = params[:user][:login] - unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank? - @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation] - end + projectActive = Project.project_entities.active + @projectCount = projectActive.count + @projectPublicCount = projectActive.all_public.count + @projectHidenCount = @projectCount - @projectPublicCount - case Setting.self_registration - when '1' - register_by_email_activation(@user) - when '3' - register_automatically(@user) - else - register_manually_by_administrator(@user) - end - end - end - - #add by huang - # @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) - - # events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - # @events_by_day = events.group_by(&:event_date) - - # + @developerCount = User.developer.count end def robots @@ -75,9 +35,9 @@ class WelcomeController < ApplicationController end def course - @course = Project.course_entities - @teacher = User.teacher - @student = User.student + @courseCount = Project.course_entities.count + @teacherCount = User.teacher.count + @studentCount = User.student.count end def contest @@ -126,9 +86,31 @@ class WelcomeController < ApplicationController end def entry_select_user - if request.original_url.match(/user\.trustie\.net/) + if request.original_url.match(/user\.trustie\.net$/) redirect_to(:controller => "users", :action => "index") return 0 end end + + def render(*args) + _fake if @fake_filter + super + end + + private + + def fake + @fake_filter = true + end + + # 楠楀瓙鏂规硶 + def _fake + instance_variables.map { |variable| + if variable.to_s =~ /Count$/ + self.instance_variable_set(variable.to_sym, + ("1" + (self.instance_variable_get(variable.to_sym).to_s)).to_i) + end + } + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6047fcf2b..0ad4404d9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1103,14 +1103,6 @@ module ApplicationHelper url end - # 瀹屾垚姣 鍔熻兘 - # 鍏蜂綋淇℃伅鍙傝僡ccount_controller#logout - def is_logout? - ret = cookies[:login_flag] == 1 ? true : false - cookies.delete(:login_flag) - ret - end - def back_url_hidden_field_tag url = back_url hidden_field_tag('back_url', url, :id => nil) unless url.blank? @@ -1482,12 +1474,20 @@ module ApplicationHelper def hadcommittedhomework(cur,curb) - @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") - @attaches.each do |attach| - if attach.user_id == cur - return true - end + bid = Bid.find_by_id(curb) + return true if bid.nil? + + case bid.homework_type + when Bid::HomeworkFile + attaches = HomeworkAttach.where(bid_id: curb) + attaches.map(&:user_id).include? cur + when Bid::HomeworkProject + attaches = BidingProject.where(user_id: User.current, bid_id: bid) + attaches.count > 0 # > 0 鍒欐湁鎻愪氦璁板綍 + else + true end + end def render_dynamic_nav diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 4d51a84ce..7259e9d10 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -70,15 +70,6 @@ module AttachmentsHelper User.current.logged? && (container.author == user || user.admin?) end - def hadcommittedhomework(cur,curb) - @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") - @attaches.each do |attach| - if attach.user_id == cur - retrun true - end - end - end - # this method is used to get all projects that tagged one tag # added by william def get_attachments_by_tag(tag_name) diff --git a/app/models/bid.rb b/app/models/bid.rb index d5177116e..fd389c15f 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -1,11 +1,20 @@ ####by fq =begin bid涓绫诲鐢紝鏍规嵁reward_type瀛楁鍒嗙被 -reward == 1 浼佷笟浼楀寘闇姹 -reward == 2 鍒涙柊绔炶禌 -reward == 3 璇剧▼涓竷缃殑浣滀笟 +reward_type == 1 浼佷笟浼楀寘闇姹 +reward_type == 2 鍒涙柊绔炶禌 +reward_type == 3 璇剧▼涓竷缃殑浣滀笟 + +homework_type浣滀笟绫诲瀷 +homework_type == 1 鏂囦欢鎻愪氦 +homework_type == 2 Project鎻愪氦 =end class Bid < ActiveRecord::Base + Enterprise = 1 + Contest = 2 + Homework = 3 + HomeworkFile = 1 + HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes diff --git a/app/models/project.rb b/app/models/project.rb index fd576b637..3fe868792 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -109,7 +109,7 @@ class Project < ActiveRecord::Base validates_presence_of :name, :identifier validates_uniqueness_of :identifier validates_associated :repository, :wiki - validates_length_of :description, :maximum => 255 + # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 validates_length_of :homepage, :maximum => 255 validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH diff --git a/app/models/user.rb b/app/models/user.rb index 4042fd84f..b9d752eb6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -82,6 +82,7 @@ class User < Principal #####fq has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy + has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy has_many :bids, :foreign_key => 'author_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" @@ -123,10 +124,16 @@ class User < Principal ## end scope :teacher, -> { - joins(:user_extensions).where('user_extensions.identity = ?', 0) + joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER) } scope :student, -> { - joins(:user_extensions).where('user_extensions.identity = ?', 1) + joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::STUDENT) + } + scope :developer, -> { + joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::DEVELOPER) + } + scope :enterprise, -> { + joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::ENTERPRISE) } attr_accessor :password, :password_confirmation diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb index 1ab3b4a69..7f729552e 100644 --- a/app/views/account/register.html.erb +++ b/app/views/account/register.html.erb @@ -287,7 +287,7 @@ <% end %>