diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cfa2e2bf0..8ba2ce20f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -234,8 +234,8 @@ class IssuesController < ApplicationController @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) # 给该issue在它所在的项目中所有的issues中所在的位置给一个序号 @issue.project_issues_index = @issue.project.issues.last.nil? ? 1 : @issue.project.issues.last.project_issues_index + 1 + @issue.fixed_version_id = nil if @issue.fixed_version_id == 0 if @issue.save - senduser = User.find(params[:issue][:assigned_to_id]) issue_id = @issue.id issue_title = params[:issue][:subject] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b1007ac8b..107f2ff88 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -27,7 +27,7 @@ class ProjectsController < ApplicationController menu_item :feedback, :only => :feedback menu_item :share, :only => :share - before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project] + before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project, :forked_pop] before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] @@ -533,7 +533,7 @@ class ProjectsController < ApplicationController @project.update_attribute(:is_public, 1) end end - # by young + # include CoursesHelper def member # 消息"同意加入项目" @@ -597,6 +597,10 @@ class ProjectsController < ApplicationController end + def member_forked + @members_forked = User.find_by_sql("SELECT u.* FROM `projects` p,`users` u where p.user_id = u.id and p.forked_from_project_id = #{@project.id} ;") + end + def update_message_status(user, project) # 更新加入项目消息 project__messages = ForgeMessage.where("forge_message_type in ('ProjectInvite', 'JoinProject', 'RemoveFromProject') and user_id =? and project_id =? ", user, project) @@ -756,6 +760,13 @@ class ProjectsController < ApplicationController redirect_to admin_projects_url(:status => params[:status]) end + # 资源库fork弹框 + def forked_pop + respond_to do |format| + format.js + end + end + def close @project.close redirect_to project_url(@project) @@ -942,5 +953,4 @@ class ProjectsController < ApplicationController return projects end #gcmend - end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index bd6c67f58..0e8ca71c0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -40,7 +40,7 @@ class RepositoriesController < ApplicationController # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] # 版本库新增权限 # before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ] accept_rss_auth :revisions @@ -87,35 +87,34 @@ class RepositoriesController < ApplicationController end def forked - @project = Project.find(params[:id]) - @repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab") - # 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项 - unless has_forked?(@project, User.current) - project = project_from_current_project(@project.id, User.current.id) - redirect_to project_path(project) - else - # 自己不能fork自己的项目 - if User.current.id == @project.user_id - flash[:notice] = l(:project_gitlab_fork_own) - redirect_to repository_url(@repository) - else - g = Gitlab.client - if User.current.gid.nil? - begin - g.sync_user(User.current) - ensure - logger.error "Synv user failed ==>#{User.current.id}" + @project = Project.find(params[:id]) + @repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab") + # 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项 + unless has_forked?(@project, User.current) + project = project_from_current_project(@project.id, User.current.id) + redirect_to project_path(project) + else + # 自己不能fork自己的项目 + if User.current.id == @project.user_id + flash[:notice] = l(:project_gitlab_fork_own) + redirect_to repository_url(@repository) + else + g = Gitlab.client + if User.current.gid.nil? + begin + g.sync_user(User.current) + ensure + logger.error "Synv user failed ==>#{User.current.id}" + end + end + gproject = g.fork(@project.gpid, User.current.gid) + if gproject + copy_project(@project, gproject) + forked_count = @project.forked_count.to_i + 1 + @project.update_attributes(:forked_count => forked_count) + end end end - gproject = g.fork(@project.gpid, User.current.gid) - if gproject - copy_project(@project, gproject) - forked_count = @project.forked_count.to_i + 1 - @project.update_attributes(:forked_count => forked_count) - end - end - end - end # 一键ZIP下载 @@ -262,6 +261,7 @@ update end @repository.project = @project @repository.type = 'Repository::Gitlab' + @repository.identifier = @repository.identifier.downcase @repository.url = @repository.identifier if request.post? && @repository.save s = Trustie::Gitlab::Sync.new @@ -477,8 +477,14 @@ update end def entry + # 顶部导航 + @project_menu_type = 5 + entry_and_raw(false) @content = @repository.cat(@path, @rev) + @changesets_latest_coimmit = @g.commit(@project.gpid, @entry.try(:lastrev)) + # 总的提交数 + @changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count if is_entry_text_data?(@content, @path) render :layout => 'base_projects' end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c95366835..b1d458d49 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1137,7 +1137,7 @@ class UsersController < ApplicationController def user_import_resource @user = User.current user_course_ids = @user.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + @attachments = Attachment.where("(author_id = #{@user.id} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") @type = params[:type] @homework_id = params[:homework_id] @@ -1156,26 +1156,22 @@ class UsersController < ApplicationController #引入资源列表根据类型过滤 def user_resource_type - if User.current.id.to_i != params[:id].to_i - render_403 - return - end user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(User.current.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(User.current.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end elsif params[:type] == "6" # 公共资源 if params[:status] == "2" @@ -1207,11 +1203,7 @@ class UsersController < ApplicationController #引入资源列表根据关键词过滤 - def user_ref_resource_search - if User.current.id.to_i != params[:id].to_i - render_403 - return - end + def user_ref_resource_searc @resource_id = params[:mul_id] @resource_type = params[:mul_type] @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -1225,7 +1217,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) + @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) elsif (params[:type].blank? || params[:type] == "6") # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) @@ -2041,7 +2033,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - @user = User.find(params[:id]) + @user = User.current # 保存文件 attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -2050,16 +2042,16 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(@user.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(@user.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) end elsif params[:type] == "6" # 公共资源 if params[:status] == "2" @@ -2109,16 +2101,16 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(@user.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(@user.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) end elsif params[:type] == "6" # 公共资源 if params[:status] == "2" @@ -2248,16 +2240,16 @@ class UsersController < ApplicationController if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(User.current.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(User.current.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @@ -2408,16 +2400,16 @@ class UsersController < ApplicationController if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(User.current.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(User.current.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @@ -2549,16 +2541,16 @@ class UsersController < ApplicationController if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(User.current.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(User.current.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @@ -3061,16 +3053,16 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources(params[:id], @order, @score) + @attachments = get_attch_resources(User.current.id, @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources(params[:id], @order, @score) + @attachments = get_principal_resources(User.current.id, @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end elsif (params[:type] == "6") # 公共资源 if params[:status] == "2" @@ -3115,11 +3107,6 @@ class UsersController < ApplicationController # 导入资源 def import_resources - # 别人的资源库是没有权限去看的 - if User.current.id != params[:id].to_i - render_403 - return - end @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id] @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project" @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -3128,7 +3115,7 @@ class UsersController < ApplicationController user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) @@ -3149,10 +3136,6 @@ class UsersController < ApplicationController end def import_resources_search - if User.current.id.to_i != params[:id].to_i - render_403 - return - end @resource_id = params[:mul_id] @resource_type = params[:mul_type] @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @@ -3166,7 +3149,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) + @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) @@ -3253,16 +3236,16 @@ class UsersController < ApplicationController user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 if params[:status] == "2" - @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search) + @attachments = get_course_resources_search(User.current.id, user_course_ids, @order, @score, search) elsif params[:status] == "3" - @attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search) + @attachments = get_project_resources_search(User.current.id, user_project_ids, @order, @score, search) elsif params[:status] == "4" - @attachments = get_attch_resources_search(params[:id], @order, @score, search) + @attachments = get_attch_resources_search(User.current.id, @order, @score, search) elsif params[:status] == "5" - @attachments = get_principal_resources_search(params[:id], @order, @score, search) + @attachments = get_principal_resources_search(User.current.id, @order, @score, search) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) + @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) end elsif params[:type] == "6" # 公共资源 if params[:status] == "2" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cf90e58a6..c32f6c175 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -67,12 +67,12 @@ module ApplicationHelper end # 重置user_path,目的是将id转换成用户名 - # def user_path(resource, parameters = {}) - # if Fixnum === resource - # resource = User.find(resource) - # end - # super - # end + def user_path(resource, parameters = {}) + if Fixnum === resource + resource = User.find(resource) + end + super + end # 历史数据(老版本库数据)处理完则可以修改该放放 def get_rep_identifier_by_project project diff --git a/app/models/user.rb b/app/models/user.rb index c226e2a52..8f7939bb3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -322,9 +322,9 @@ class User < Principal end # id 转换成 登录名 - # def to_param - # self.login.to_i > 0 ? id : login - # end + def to_param + self.login.to_i > 0 ? id : login + end def my_blogs_count diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index f302190b2..f5b5692f3 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -2,63 +2,6 @@ input.is_public,input.is_public_checkbox{height:12px;} input.is_public_checkbox{margin-left:4px;margin-right:4px;} -