From fee81455db9b712b08876adbe5115f6111427ac6 Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 19 Aug 2013 08:48:21 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 27 ++++++++++------------ config/locales/zh.yml | 2 ++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a2167bdf..87b75891 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -76,6 +76,8 @@ class RepositoriesController < ApplicationController @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] + @middle=User.current.login.to_s+"-"+params[:repository][:identifier]+"-write:" attrs = pickup_extra_info if((@repository_tag!="")&¶ms[:repository_scm]=="Git") params[:repository][:url]=@project_path @@ -91,23 +93,19 @@ class RepositoriesController < ApplicationController @repository.project = @project if request.post? && @repository.save if(params[:repository_scm]=="Git") - system "htpasswd -mb "+@root_path+"user.passwd "+User.current.login.to_s+" "+@repository_tag - system "echo -e '\n"+User.current.login.to_s+"-"+params[:repository][:identifier]+"-write:"+ - " "+User.current.login.to_s+"' >> "+@root_path+"group.passwd" + system "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag + system "echo -e '\n"+@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 "+User.current.login.to_s+"-"+params[:repository][:identifier]+"-write \n "+ + "Require group "+@repo_name+"-write \n "+ " \n ' >> "+ - @root_path+"htdocs/"+ @repository_name+"/.htaccess" - - puts "before ======================================================================" - puts system "cd "+@project_path+" ;git update-server-info" - flag = system "cd "+@project_path+" ;git update-server-info" - puts "after flag:#{flag} ======================================================================" + @root_path+"htdocs/"+ @repository_name+"/.htaccess" + flag = system "cd "+@project_path+" ;git update-server-info" @repository.update_attributes(:login => User.current.login.to_s) end redirect_to settings_project_path(@project, :tab => 'repositories') @@ -170,11 +168,10 @@ class RepositoriesController < ApplicationController @repository_name=User.current.login.to_s+"/"+@repository.identifier.to_s+".git" @repository.destroy if request.delete? redirect_to settings_project_path(@project, :tab => 'repositories') - if(@repository.type=="Repository::Git") - puts "before destroy system cmd =======================================" - puts "rm -r "+@root_path+@repository_name - flag = system "rm -r "+@root_path+"htdocs/"+@repository_name - puts "after destroy system cmd :#{flag} =======================================" + if(@repository.type=="Repository::Git") + system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" + system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" + system "rm -r "+@root_path+"htdocs/"+@repository_name end end diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7c410073..96ae7562 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1261,9 +1261,11 @@ zh: label_tags_user_mail: 用户邮箱: label_tags_numbers: Tag统计: label_max_number: 至多25个字符。 + label_mail_attention: qq邮箱可能收不到此邮件,其他邮箱如果没有收到可能在垃圾邮件中 label_all_revisions: 所有版本: label_upassword_info: 该密码在项目组内可共享 label_how_commit_code: 如何提交代码: label_how_commit_code_chinese: 中文 label_welcome_leave_message: 朋友,系统仍在不断完善,有意见和建议请 label_welcome_click_me: 点击我 + label_mail_attention: qq邮箱可能收不到此邮件,其他邮箱如果没有收到可能在垃圾邮件中 From 9dc4fcaa8e025846ce930221655d7f4570953f16 Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 19 Aug 2013 10:24:02 +0800 Subject: [PATCH 2/5] add logger info --- app/controllers/repositories_controller.rb | 29 ++-- lib/git/backend/grack_auth.rb | 119 +++++++++++++++++ lib/git/backend/grack_helpers.rb | 28 ++++ lib/git/backend/grack_ldap.rb | 24 ++++ lib/git/backend/shell.rb | 148 +++++++++++++++++++++ lib/git/backend/shell_adapter.rb | 12 ++ lib/git/backend/shell_env.rb | 17 +++ 7 files changed, 367 insertions(+), 10 deletions(-) create mode 100644 lib/git/backend/grack_auth.rb create mode 100644 lib/git/backend/grack_helpers.rb create mode 100644 lib/git/backend/grack_ldap.rb create mode 100644 lib/git/backend/shell.rb create mode 100644 lib/git/backend/shell_adapter.rb create mode 100644 lib/git/backend/shell_env.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 87b75891..383aec7a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -93,19 +93,24 @@ class RepositoriesController < ApplicationController @repository.project = @project if request.post? && @repository.save if(params[:repository_scm]=="Git") - system "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag - system "echo -e '\n"+@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 + @create_passwd = system "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag + @create_group = system "echo -e '\n"+@repo_name+"-write:"+ + " "+@repo_name+"' >> "+@root_path+"group.passwd" + @create_repo_file = system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s + @init_repository = 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 "+ + @add_privilege = 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" - flag = system "cd "+@project_path+" ;git update-server-info" + @init_server_info = system "cd "+@project_path+" ;git update-server-info" + if(@create_repo_file&&@create_passwd&&@create_group&&@init_repository&&@add_privilege&&@init_server_info) + logger.error "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') @@ -169,9 +174,13 @@ class RepositoriesController < ApplicationController @repository.destroy if request.delete? redirect_to settings_project_path(@project, :tab => 'repositories') if(@repository.type=="Repository::Git") - system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" - system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" - system "rm -r "+@root_path+"htdocs/"+@repository_name + @ed_user=system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" + @sed_group=system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" + @remove=system "rm -r "+@root_path+"htdocs/"+@repository_name + if(@sed_user&&@sed_group&&@remove) + logger.error "An error occured when destory the repository"+"delete form passwd: \n"+ + @sed_user+"delete from group"+@sed_group+"delete from file"+@remove + end end end diff --git a/lib/git/backend/grack_auth.rb b/lib/git/backend/grack_auth.rb new file mode 100644 index 00000000..e7217c7c --- /dev/null +++ b/lib/git/backend/grack_auth.rb @@ -0,0 +1,119 @@ +require_relative 'shell_env' +require_relative 'grack_ldap' +require_relative 'grack_helpers' + +module Grack + class Auth < Rack::Auth::Basic + include LDAP + include Helpers + + attr_accessor :user, :project, :ref, :env + + def call(env) + @env = env + @request = Rack::Request.new(env) + @auth = Request.new(env) + + # Need this patch due to the rails mount + @env['PATH_INFO'] = @request.path + @env['SCRIPT_NAME'] = "" + + auth! + end + + private + + def auth! + return render_not_found unless project + + if @auth.provided? + return bad_request unless @auth.basic? + + # Authentication with username and password + login, password = @auth.credentials + + @user = authenticate_user(login, password) + + if @user + Gitlab::ShellEnv.set_env(@user) + @env['REMOTE_USER'] = @auth.username + else + return unauthorized + end + + else + return unauthorized unless project.public + end + + if authorized_git_request? + @app.call(env) + else + unauthorized + end + end + + def authorized_git_request? + # Git upload and receive + if @request.get? + authorize_request(@request.params['service']) + elsif @request.post? + authorize_request(File.basename(@request.path)) + else + false + end + end + + def authenticate_user(login, password) + user = User.find_by_email(login) || User.find_by_username(login) + + # If the provided login was not a known email or username + # then user is nil + if user.nil? || user.ldap_user? + # Second chance - try LDAP authentication + return nil unless ldap_conf.enabled + + auth = Gitlab::Auth.new + auth.ldap_auth(login, password) + else + return user if user.valid_password?(password) + end + end + + def authorize_request(service) + case service + when 'git-upload-pack' + project.public || can?(user, :download_code, project) + when'git-receive-pack' + action = if project.protected_branch?(ref) + :push_code_to_protected_branches + else + :push_code + end + + can?(user, action, project) + else + false + end + end + + def project + @project ||= project_by_path(@request.path_info) + end + + def ref + @ref ||= parse_ref + end + + def parse_ref + input = if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/ + Zlib::GzipReader.new(@request.body).read + else + @request.body.read + end + + # Need to reset seek point + @request.body.rewind + /refs\/heads\/([\w\.-]+)/n.match(input.force_encoding('ascii-8bit')).to_a.last + end + end +end diff --git a/lib/git/backend/grack_helpers.rb b/lib/git/backend/grack_helpers.rb new file mode 100644 index 00000000..5ac9e9f3 --- /dev/null +++ b/lib/git/backend/grack_helpers.rb @@ -0,0 +1,28 @@ +module Grack + module Helpers + def project_by_path(path) + if m = /^\/([\w\.\/-]+)\.git/.match(path).to_a + path_with_namespace = m.last + path_with_namespace.gsub!(/\.wiki$/, '') + + Project.find_with_namespace(path_with_namespace) + end + end + + def render_not_found + [404, {"Content-Type" => "text/plain"}, ["Not Found"]] + end + + def can?(object, action, subject) + abilities.allowed?(object, action, subject) + end + + def abilities + @abilities ||= begin + abilities = Six.new + abilities << Ability + abilities + end + end + end +end diff --git a/lib/git/backend/grack_ldap.rb b/lib/git/backend/grack_ldap.rb new file mode 100644 index 00000000..45e98fba --- /dev/null +++ b/lib/git/backend/grack_ldap.rb @@ -0,0 +1,24 @@ +require 'omniauth-ldap' + +module Grack + module LDAP + def ldap_auth(login, password) + # Check user against LDAP backend if user is not authenticated + # Only check with valid login and password to prevent anonymous bind results + return nil unless ldap_conf.enabled && !login.blank? && !password.blank? + + ldap = OmniAuth::LDAP::Adaptor.new(ldap_conf) + ldap_user = ldap.bind_as( + filter: Net::LDAP::Filter.eq(ldap.uid, login), + size: 1, + password: password + ) + + User.find_by_extern_uid_and_provider(ldap_user.dn, 'ldap') if ldap_user + end + + def ldap_conf + @ldap_conf ||= Gitlab.config.ldap + end + end +end diff --git a/lib/git/backend/shell.rb b/lib/git/backend/shell.rb new file mode 100644 index 00000000..991648f3 --- /dev/null +++ b/lib/git/backend/shell.rb @@ -0,0 +1,148 @@ +module Gitlab + class Shell + class AccessDenied < StandardError; end + + # Init new repository + # + # name - project path with namespace + # + # Ex. + # add_repository("gitlab/gitlab-ci") + # + def add_repository(name) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "add-project", "#{name}.git" + end + + # Import repository + # + # name - project path with namespace + # + # Ex. + # import_repository("gitlab/gitlab-ci", "https://github.com/randx/six.git") + # + def import_repository(name, url) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "import-project", "#{name}.git", url + end + + # Move repository + # + # path - project path with namespace + # new_path - new project path with namespace + # + # Ex. + # mv_repository("gitlab/gitlab-ci", "randx/gitlab-ci-new.git") + # + def mv_repository(path, new_path) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "mv-project", "#{path}.git", "#{new_path}.git" + end + + # Fork repository to new namespace + # + # path - project path with namespace + # fork_namespace - namespace for forked project + # + # Ex. + # fork_repository("gitlab/gitlab-ci", "randx") + # + def fork_repository(path, fork_namespace) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "fork-project", "#{path}.git", fork_namespace + end + + # Remove repository from file system + # + # name - project path with namespace + # + # Ex. + # remove_repository("gitlab/gitlab-ci") + # + def remove_repository(name) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-project", "#{name}.git" + end + + # Add new key to gitlab-shell + # + # Ex. + # add_key("key-42", "sha-rsa ...") + # + def add_key(key_id, key_content) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys", "add-key", key_id, key_content + end + + # Remove ssh key from gitlab shell + # + # Ex. + # remove_key("key-342", "sha-rsa ...") + # + def remove_key(key_id, key_content) + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys", "rm-key", key_id, key_content + end + + # Add empty directory for storing repositories + # + # Ex. + # add_namespace("gitlab") + # + def add_namespace(name) + FileUtils.mkdir(full_path(name), mode: 0770) unless exists?(name) + end + + # Remove directory from repositories storage + # Every repository inside this directory will be removed too + # + # Ex. + # rm_namespace("gitlab") + # + def rm_namespace(name) + FileUtils.rm_r(full_path(name), force: true) + end + + # Move namespace directory inside repositories storage + # + # Ex. + # mv_namespace("gitlab", "gitlabhq") + # + def mv_namespace(old_name, new_name) + return false if exists?(new_name) || !exists?(old_name) + + FileUtils.mv(full_path(old_name), full_path(new_name)) + end + + # Remove GitLab Satellites for provided path (namespace or repo dir) + # + # Ex. + # rm_satellites("gitlab") + # + # rm_satellites("gitlab/gitlab-ci.git") + # + def rm_satellites(path) + raise ArgumentError.new("Path can't be blank") if path.blank? + + satellites_path = File.join(Gitlab.config.satellites.path, path) + FileUtils.rm_r(satellites_path, force: true) + end + + def url_to_repo path + Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git" + end + + protected + + def gitlab_shell_user_home + File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}") + end + + def repos_path + Gitlab.config.gitlab_shell.repos_path + end + + def full_path(dir_name) + raise ArgumentError.new("Directory name can't be blank") if dir_name.blank? + + File.join(repos_path, dir_name) + end + + def exists?(dir_name) + File.exists?(full_path(dir_name)) + end + end +end diff --git a/lib/git/backend/shell_adapter.rb b/lib/git/backend/shell_adapter.rb new file mode 100644 index 00000000..f247f459 --- /dev/null +++ b/lib/git/backend/shell_adapter.rb @@ -0,0 +1,12 @@ +# == GitLab Shell mixin +# +# Provide a shortcut to Gitlab::Shell instance by gitlab_shell +# +module Gitlab + module ShellAdapter + def gitlab_shell + Gitlab::Shell.new + end + end +end + diff --git a/lib/git/backend/shell_env.rb b/lib/git/backend/shell_env.rb new file mode 100644 index 00000000..15721875 --- /dev/null +++ b/lib/git/backend/shell_env.rb @@ -0,0 +1,17 @@ +module Gitlab + # This module provide 2 methods + # to set specific ENV variabled for GitLab Shell + module ShellEnv + extend self + + def set_env(user) + # Set GL_ID env variable + ENV['GL_ID'] = "user-#{user.id}" + end + + def reset_env + # Reset GL_ID env variable + ENV['GL_ID'] = nil + end + end +end From a12608357918ef4b2e43c57a270ae35d733c795f Mon Sep 17 00:00:00 2001 From: nieguanghui Date: Mon, 19 Aug 2013 16:41:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=98=BE=E7=A4=BA=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d268e100..e99ff4ee 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1311,6 +1311,9 @@ module ApplicationHelper def show_watcher_profile(obj) count = 0 html = '' + if User.watched_by(obj.id).count == 0 + html << (content_tag "span", l(:label_no_current_watchers)) + end for user in User.watched_by(obj.id) html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") count = count + 1 @@ -1333,6 +1336,9 @@ module ApplicationHelper def show_fans_picture(obj) html = '' count = 0 + if obj.watcher_users.count == 0 + html << (content_tag "span", l(:label_no_current_fans)) + end for user in obj.watcher_users html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => "#{user.name}") count = count + 1 From 02239e8cd263e06dbf38230a401e1521935edc9f Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 19 Aug 2013 17:07:07 +0800 Subject: [PATCH 4/5] modify --- app/controllers/repositories_controller.rb | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 383aec7a..2c6b92d0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -93,24 +93,26 @@ class RepositoriesController < ApplicationController @repository.project = @project if request.post? && @repository.save if(params[:repository_scm]=="Git") - @create_passwd = system "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag - @create_group = system "echo -e '\n"+@repo_name+"-write:"+ + system "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag + logger.info "htpasswd -mb "+@root_path+" "+@repo_name+" "+@repository_tag+create_passwd + system "echo -e '\n"+@repo_name+"-write:"+ " "+@repo_name+"' >> "+@root_path+"group.passwd" - @create_repo_file = system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s - @init_repository = system "git init --bare "+@project_path + 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" - @add_privilege = system "echo -e 'Allow from all \n Order Deny,Allow \n "+ + 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" - @init_server_info = system "cd "+@project_path+" ;git update-server-info" - if(@create_repo_file&&@create_passwd&&@create_group&&@init_repository&&@add_privilege&&@init_server_info) - logger.error "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 + 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') @@ -174,13 +176,14 @@ class RepositoriesController < ApplicationController @repository.destroy if request.delete? redirect_to settings_project_path(@project, :tab => 'repositories') if(@repository.type=="Repository::Git") - @ed_user=system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" - @sed_group=system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" - @remove=system "rm -r "+@root_path+"htdocs/"+@repository_name - if(@sed_user&&@sed_group&&@remove) - logger.error "An error occured when destory the repository"+"delete form passwd: \n"+ - @sed_user+"delete from group"+@sed_group+"delete from file"+@remove - end + system "sed -i /"+@repo_name+"/{d} "+@root_path+"user.passwd" + system "sed -i /"+@middle+"/{d} "+@root_path+"group.passwd" + system "rm -r "+@root_path+"htdocs/"+@repository_name + # if(@sed_user&&@sed_group&&@remove) + # else + # logger.info "An error occured when destory the repository"+"delete form passwd: \n"+ + # @sed_user+"delete from group"+@sed_group+"delete from file"+@remove + # end end end From d62ad9e8632a26652d040936f6e5c8628aff075c Mon Sep 17 00:00:00 2001 From: william Date: Mon, 19 Aug 2013 17:28:59 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=BB=99tag=20search=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=88=86=E9=A1=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 1 + app/controllers/tags_controller.rb | 50 ++++++++++++++++-- app/models/user.rb | 4 +- app/models/user_extensions.rb | 1 + app/views/my/account.html.erb | 11 +++- app/views/projects/index.html.erb | 2 +- app/views/tags/_related_tags.html.erb | 2 +- app/views/tags/_selected_tags.html.erb | 2 +- app/views/tags/_show_bids.html.erb | 5 ++ app/views/tags/_show_issues.html.erb | 5 ++ app/views/tags/_show_projects.html.erb | 6 ++- app/views/tags/_show_users.html.erb | 5 ++ app/views/tags/_tag.html.erb | 2 +- app/views/tags/_tag_search_results.html.erb | 4 +- app/views/tags/index.html.erb | 7 +-- app/views/users/_user_extensions.html.erb | 26 +++++++++ config/locales/zh.yml | 12 +++++ config/settings.yml | 8 +-- public/images/praise_tread/praise_false.png | Bin 2878 -> 2877 bytes public/images/praise_tread/praise_true.png | Bin 2875 -> 2877 bytes public/images/praise_tread/tread_false.png | Bin 2889 -> 2884 bytes public/images/praise_tread/tread_true.png | Bin 2884 -> 2883 bytes .../stylesheets/application.css | 5 +- 23 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 app/views/users/_user_extensions.html.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 6b8c0366..8ef71924 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -15,6 +15,7 @@ class BidsController < ApplicationController @bids = @bids.like(params[:name]) if params[:name].present? @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] + @offset ||= @bid_pages.reverse_offset #@bids = @bids.offset(@offset).limit(@limit).all.reverse unless @offset == 0 diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ab05474f..ccfeccd6 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -7,6 +7,7 @@ class TagsController < ApplicationController include UsersHelper include BidsHelper include ActsAsTaggableOn::TagsHelper + helper :projects $selected_tags = Array.new $related_tags = Array.new @@ -21,23 +22,56 @@ class TagsController < ApplicationController @users_tags_num = User.tag_counts.size @bids_tags_num = Bid.tag_counts.size - @issues_results = get_issues_by_tag($selected_tags) - @projects_results = get_projects_by_tag($selected_tags) - @users_results = get_users_by_tag($selected_tags) - @bids_results = get_bids_by_tag($selected_tags) + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 + @users_results = nil + @projects_results = nil + @issues_results = nil + @bids_results = nil + @obj_pages = nil @obj_id = params[:obj_id] @obj_flag = params[:object_flag] + @numbers = Setting.tags_show_search_results case @obj_flag when '1' then + @users_results = get_users_by_tag($selected_tags) @obj = User.find_by_id(@obj_id) + + @offset, @limit = api_offset_and_limit({:limit => @numbers}) + @project_count = @users_results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + @users_results = @users_results.offset(@offset).limit(@limit).all when '2' then + @projects_results = get_projects_by_tag($selected_tags) @obj = Project.find_by_id(@obj_id) + + @offset, @limit = api_offset_and_limit({:limit => @numbers}) + @project_count = @projects_results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + @projects_results = @projects_results.offset(@offset).limit(@limit).order('lft').all + when '3' then + @issues_results = get_issues_by_tag($selected_tags) @obj = Issue.find_by_id(@obj_id) + + @offset, @limit = api_offset_and_limit({:limit => @numbers}) + @project_count = @issues_results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + @issues_results = @issues_results.offset(@offset).limit(@limit).all when '4' + @bids_results = get_bids_by_tag($selected_tags) @obj = Bid.find_by_id(@obj_id) + + @offset, @limit = api_offset_and_limit({:limit => @numbers}) + @project_count = @bids_results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + @bids_results = @bids_results.offset(@offset).limit(@limit).all + else @obj = nil end @@ -83,4 +117,12 @@ class TagsController < ApplicationController end + def for_pagination(results) + @offset, @limit = api_offset_and_limit({:limit => 2}) + @project_count = results.count + @obj_pages = Paginator.new @project_count, @limit, params['page'] + @offset ||= @obj_pages.offset + results = results.offset(@offset).limit(@limit).order('lft').all + end + end diff --git a/app/models/user.rb b/app/models/user.rb index e27c6a78..ae672b53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,7 +99,9 @@ class User < Principal acts_as_taggable scope :by_join_date, order("created_at DESC") ############################# added by liuping 关注 - acts_as_watchable + acts_as_watchable + has_one :user_extensions + ## end attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index f70cddad..47578e66 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -1,4 +1,5 @@ class UserExtensions < ActiveRecord::Base + belongs_to :user attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code #this method was used to update the table user_extensions def update_user_extensions(birthday=nil,brief_introduction=nil, diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 9a75481a..2143dee6 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -5,8 +5,6 @@

<%= l(:label_my_account)%>

- -
+ + + <%= submit_tag l(:button_save) %>
<% end %> diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 4435727f..8f4852ef 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -25,7 +25,7 @@ diff --git a/app/views/tags/_related_tags.html.erb b/app/views/tags/_related_tags.html.erb index 84fb0692..42b3c010 100644 --- a/app/views/tags/_related_tags.html.erb +++ b/app/views/tags/_related_tags.html.erb @@ -1,5 +1,5 @@ <% if related_tags %> -
    +
      <% for rt in related_tags %>
    • <%= link_to image_tag("/images/sidebar/add.png"),:action => "add_tag",:remote => true,:tag => rt,:show_flag => show_flag %> diff --git a/app/views/tags/_selected_tags.html.erb b/app/views/tags/_selected_tags.html.erb index f3afa4d8..78f96374 100644 --- a/app/views/tags/_selected_tags.html.erb +++ b/app/views/tags/_selected_tags.html.erb @@ -1,5 +1,5 @@ <% if selected_tags %> -
        +
          <% for sg in selected_tags %>
        • <%= link_to image_tag("/images/sidebar/minus.png"),:action => "delete_tag",:remote=>true,:tag => sg,:show_flag => show_flag %> diff --git a/app/views/tags/_show_bids.html.erb b/app/views/tags/_show_bids.html.erb index fd46f87f..4e808829 100644 --- a/app/views/tags/_show_bids.html.erb +++ b/app/views/tags/_show_bids.html.erb @@ -10,4 +10,9 @@
          <% end %> <% end %> + + \ No newline at end of file diff --git a/app/views/tags/_show_issues.html.erb b/app/views/tags/_show_issues.html.erb index e29edb30..32654e40 100644 --- a/app/views/tags/_show_issues.html.erb +++ b/app/views/tags/_show_issues.html.erb @@ -12,3 +12,8 @@ <% end %> + diff --git a/app/views/tags/_show_projects.html.erb b/app/views/tags/_show_projects.html.erb index aa9f5874..7e706ddd 100644 --- a/app/views/tags/_show_projects.html.erb +++ b/app/views/tags/_show_projects.html.erb @@ -11,6 +11,10 @@
          <% end %> - <% end %> + \ No newline at end of file diff --git a/app/views/tags/_show_users.html.erb b/app/views/tags/_show_users.html.erb index 7ce8328f..552b7b6b 100644 --- a/app/views/tags/_show_users.html.erb +++ b/app/views/tags/_show_users.html.erb @@ -11,4 +11,9 @@
          <% end %> <% end %> + + \ No newline at end of file diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 8c2c3d90..123e9ef3 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -41,7 +41,7 @@ <%= form_for "tag_for_save",:remote=>true,:url=>tag_path, :update => "tags_show", :complete => '$("#put-tag-form").hide();' do |f| %> - <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => 25,:minlength=>1 %> + <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length %> <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%> <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%> <%= f.submit "add"%> diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index 9e816af8..bb584c91 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -3,7 +3,7 @@ <% case %> <% when show_flag == '1' %> <%=l(:label_user)%> - <%= render :partial => "show_users",:locals => {:users_results => users_results }%> + <%= render :partial => "show_users",:locals => {:users_results => users_results}%> <% when show_flag == '2'%> <%=l(:label_project)%> <%= render :partial => "show_projects",:locals => {:projects_results => projects_results }%> @@ -12,7 +12,7 @@ <%= render :partial => "show_issues",:locals => {:issues_results => issues_results }%> <% when show_flag == '4'%> <%= l(:label_requirement)%> - <%= render :partial => "show_bids",:locals => {:bids_results => bids_results }%> + <%= render :partial => "show_bids",:locals => {:bids_results => bids_results}%> <% else %> <%= l(:label_tags_all_objects)%> <%= render :partial => "show_issues",:locals => {:issues_results => issues_results }%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 4fabfcf0..8e65d92e 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -1,10 +1,11 @@ <% content_for :sidebar do %>
          - Selected Tags +

          Selected Tags

          <%= render :partial => "selected_tags",:locals => {:selected_tags => $selected_tags,:show_flag => @obj_flag}%>
          - Related Tags + +

          Related Tags

          @@ -13,7 +14,7 @@ <% content_for :content do %>

          Search Results

          -
          +
          <%= l(:label_tags_numbers) %> <%= l(:label_issue_plural) %>(<%= @issues_tags_num %>)| <%= l(:label_project_plural) %>(<%= @projects_tags_num %>)| diff --git a/app/views/users/_user_extensions.html.erb b/app/views/users/_user_extensions.html.erb new file mode 100644 index 00000000..aea59356 --- /dev/null +++ b/app/views/users/_user_extensions.html.erb @@ -0,0 +1,26 @@ +<%= labelled_fields_for :user_extensions, @user.user_extensions do |user_extension| %> + +

          + <%= user_extension.text_field :birthday %> +

          +

          + <%= user_extension.select :gender, [[l(:label_boy), '1'], [l(:label_girl), '0']] %> +

          + +

          + <%= user_extension.text_area :brief_introduction %>(少于250字) +

          +

          + <%= user_extension.text_field :location %> +

          +

          + <%= user_extension.text_field :occupation %> +

          +

          + <%= user_extension.text_field :work_experience %> +

          +

          + <%= user_extension.text_field :zip_code %> +

          + +<% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 96ae7562..f5b33c5b 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1173,6 +1173,18 @@ zh: label_tags_bid_description: 需求描述 label_tags_issue_description: 问题描述 label_tags_all_objects: 所有 + + label_user_extensions: 其他信息 + label_boy: 男 + label_girl: 女 + field_gender: 性别 + field_birthday: 生日 + field_brief_introduction: 个人简介 + field_location: 现住址 + field_occupation: 学校/公司 + field_work_experience: 工作经验(年) + field_zip_code: 邮编 + #fq button_leave_meassge: 留言 label_leave_message_to: 给用户 %{name}留言 diff --git a/config/settings.yml b/config/settings.yml index 06421a5f..d05a8182 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -234,12 +234,12 @@ non_working_week_days: show_tags_length: format: int default: 5 - show_tags_length: - format: int - default: 5 tags_min_length: format: int default: 1 tags_max_length: format: int - default: 25 \ No newline at end of file + default: 13 +tags_show_search_results: + format: int + default: 5 \ No newline at end of file diff --git a/public/images/praise_tread/praise_false.png b/public/images/praise_tread/praise_false.png index 8c46ede35090277bd0dad51d3aa8cb0ad3a6bf8d..b3b7c00a244ec6d50ebde8b9d53eaae90e36f9e1 100644 GIT binary patch delta 135 zcmV;20C@kt7QGg*z6yV8Nkl`yZ;ea@9;XjfwUrc7TlrVP3SY z?!{R=PxCBc5gG4Nh?Biv5EtKE5EU~JAXBptA)h-CBCop;BaayfKyI@Tgj_Nah;$f& pk%plpm61$=(tdOR009600{{{#9=OB79|iyb002ovPDHLkV1nBhmqMKE{ermo=7Ol0fdHABg$ViFfe?A!g&29vKmc-^g&^dTi9n>o r5R5boC8>;L3Y7Mv0{{U3{{sL3EFGi}On4;#0000`ya07anb3fG130S4zST6%!{_w zy*P{KX`Ur4BI8{OakBRd;^LbNqGARDWNH>7T6S%{F~4ur_>F2qPT0|7`g3qi;y6M@JBLojk< nC`n}`Q=qgTod5s;|NjF3&7~c6#X*Iq00000NkvXXu0mjfWkor$ diff --git a/public/images/praise_tread/tread_false.png b/public/images/praise_tread/tread_false.png index 57927082b5d9a2be8f41793f2f86635f577231dc..5c06409f8f3816b85c930cc8f724d531b335b2d8 100644 GIT binary patch delta 143 zcmV;A0C4}w7Q_~?z6yVFNklqbhHAX8q5-94Tzsk5iK4wi@yn5pcNgjB3zR5Gp}$Hc|!pQlAP?@6N~u{T(%#ph$y|1&Y=c xNpHg4NXGANGNz%u+JpeZ0$l(A0RR6302zY^Ikh__`Tzg`07(Z$PDHLkV1mEIJVyWk delta 148 zcmV;F0Birm7ReT{z6yVKNklt3MZ}aKjMTD-*y4(j zN@|EM8yTtLdnO8liKKXCq96f~oPYoT009600|2R12RUc)b^Z(h0000z6yVENklon9RL6T delta 143 zcmV;A0C4}q7Q_~?z6yVFNkl7k&NHlVoXzewFLpD1-bwL0RR630G2!lIUTg`&j0`b07(Z$PDHLkV1jdII_3ZX diff --git a/public/themes/redpenny-master/stylesheets/application.css b/public/themes/redpenny-master/stylesheets/application.css index 906680a2..6635a111 100644 --- a/public/themes/redpenny-master/stylesheets/application.css +++ b/public/themes/redpenny-master/stylesheets/application.css @@ -251,6 +251,7 @@ a font-size: 11px; border-radius:3px; -moz-border-radius:3px; + -webkit-border-radius:3px; -o-border-radius:3px; -ms-border-radius:3px; @@ -1070,7 +1071,9 @@ pre,code,.line-code } - +div.project_tag_info a.root { + font-size: 1.5em; +} div.wiki-description { /*word-break; break-all;