| @@ -18,12 +18,14 @@ | |||
| class MembersController < ApplicationController | |||
| model_object Member | |||
| before_filter :find_model_object, :except => [:index, :create, :autocomplete] | |||
| before_filter :find_model_object, :except => [:index, :create, :autocomplete,:gitlabautocomplete] | |||
| #before_filter :find_model_object_contest, :except => [:index, :create, :autocomplete] | |||
| before_filter :find_project_from_association, :except => [:index, :create, :autocomplete] | |||
| before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete] | |||
| before_filter :authorize | |||
| accept_api_auth :index, :show, :create, :update, :destroy | |||
| before_filter :find_project_from_association, :except => [:index, :create, :autocomplete,:gitlabautocomplete] | |||
| before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete,:gitlabautocomplete] | |||
| before_filter :authorize, :except => [:gitlabautocomplete] | |||
| accept_api_auth :index, :show, :create, :update, :destroy | |||
| include GitlabHelper | |||
| def index | |||
| @offset, @limit = api_offset_and_limit | |||
| @@ -104,6 +106,7 @@ class MembersController < ApplicationController | |||
| end | |||
| if members.present? && members.all? { |m| m.valid? } | |||
| members.each do |member| | |||
| add_trustie_user(@project.id,member.user_id) | |||
| AppliedProject.deleteappiled(member.user_id, @project.id) | |||
| end | |||
| end | |||
| @@ -253,6 +256,8 @@ class MembersController < ApplicationController | |||
| #课程成员删除修改 | |||
| if @project | |||
| if request.delete? && @member.deletable? | |||
| # 删除gitlab用户 | |||
| delete_trustie_user(@project.id,@member.user_id) | |||
| @member.destroy | |||
| # end | |||
| user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) | |||
| @@ -314,6 +319,7 @@ class MembersController < ApplicationController | |||
| end | |||
| end | |||
| private | |||
| def redirect_to_settings_in_projects | |||
| @@ -77,6 +77,7 @@ class ProjectsController < ApplicationController | |||
| helper :words | |||
| ### added by william | |||
| include ActsAsTaggableOn::TagsHelper | |||
| include GitlabHelper | |||
| def find_project_repository | |||
| unless @project.repositories.nil? | |||
| @@ -9,7 +9,7 @@ | |||
| # This program is distributed in the hope that it will be useful, | |||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| # GNU General Public License for more details. | |||
| # GNU General Public License for more details. add_gitlab_user | |||
| # | |||
| # You should have received a copy of the GNU General Public License | |||
| # along with this program; if not, write to the Free Software | |||
| @@ -31,16 +31,17 @@ class RepositoriesController < ApplicationController | |||
| before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] | |||
| before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] | |||
| before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo] | |||
| before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:gitlabautocomplete,:add_gitlab_user] | |||
| before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] | |||
| before_filter :authorize , :except => [:newrepo,:newcreate,:fork] | |||
| before_filter :authorize , :except => [:newrepo,:newcreate,:fork,:gitlabautocomplete,:add_gitlab_user] | |||
| accept_rss_auth :revisions | |||
| # hidden repositories filter // 隐藏代码过滤器 | |||
| before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] | |||
| helper :repositories | |||
| include RepositoriesHelper | |||
| helper :repositories | |||
| include GitlabHelper | |||
| #@root_path = RepositoriesHelper::ROOT_PATH | |||
| rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed | |||
| def new | |||
| @@ -58,6 +59,9 @@ class RepositoriesController < ApplicationController | |||
| def newrepo | |||
| # modify by nwb | |||
| # 查找当前用户的gitlab账号 | |||
| @gitlab_user = GitlabUser.find_by_user_id(User.current.id) | |||
| scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first | |||
| @repository = Repository.factory(scm) | |||
| @repository.is_default = @project.repository.nil? | |||
| @@ -91,10 +95,14 @@ class RepositoriesController < ApplicationController | |||
| render :action => 'show', :layout => 'base_projects' | |||
| end | |||
| # 创建git版本库 | |||
| def create | |||
| if params[:repository_scm].to_s == 'Gitlab' | |||
| if params[:repository_scm].to_s == 'Git' | |||
| # add by nwb | |||
| # 增加对gitlab版本库的支持 | |||
| user = User.current | |||
| @gitlab_user = GitlabUser.find_by_user_id(user.id) | |||
| attrs = pickup_extra_info | |||
| @repository = Repository.factory('Git') | |||
| @repository.safe_attributes = params[:repository] | |||
| @@ -102,6 +110,56 @@ class RepositoriesController < ApplicationController | |||
| @repository.merge_extra_info(attrs[:attrs_extra]) | |||
| end | |||
| @repository.project = @project | |||
| # 数据检测 | |||
| if params[:repository][:identifier] == "" | |||
| flash[:error] = l(:project_module_repository) + l(:blank) | |||
| render :action => 'newrepo', :layout => 'base_projects' | |||
| return | |||
| elsif params[:repository][:gitlab_user] == "" | |||
| flash[:error] = l(:label_user) + l(:blank) | |||
| render :action => 'newrepo', :layout => 'base_projects' | |||
| return | |||
| elsif params[:repository][:gitlab_email] == "" | |||
| flash[:error] = l(:field_mail) + l(:blank) | |||
| render :action => 'newrepo', :layout => 'base_projects' | |||
| return | |||
| elsif params[:repository][:upassword] == "" | |||
| flash[:error] = l(:label_password) + l(:blank) | |||
| render :action => 'newrepo', :layout => 'base_projects' | |||
| return | |||
| end | |||
| # 判断gitlab用户是否存在,不存在则创建 | |||
| if @gitlab_user.nil? | |||
| if !create_user(params[:repository][:gitlab_user],user.show_name,params[:repository][:upassword],params[:repository][:gitlab_email],user.id) | |||
| # 创建gitlab用户失败 | |||
| # 验证gitlab是否可由指定的账号、密码登录 | |||
| if login_init_gitlab(params[:repository][:gitlab_email],params[:repository][:upassword],params[:repository][:gitlab_user],user.id) | |||
| @gitlab_user = GitlabUser.find_by_user_id(user.id) | |||
| else | |||
| flash[:error] = l(:error_create_gitlab_user) | |||
| render :action => 'newrepo', :layout =>'base_projects' | |||
| return | |||
| end | |||
| end | |||
| @gitlab_user = GitlabUser.find_by_user_id(user.id) | |||
| end | |||
| # 创建gitlab版本库 | |||
| repos = params[:repository][:identifier] | |||
| temp = create_project_for_user(repos,@project.id,@gitlab_user.gitlab_user_id) | |||
| if !temp[:result] | |||
| # 创建gitlab项目失败 | |||
| flash[:error] = l(:error_create_gitlab_project) | |||
| render :action => 'newrepo', :layout =>'base_projects' | |||
| return | |||
| end | |||
| # 连接创建成功后的gitlab版本库 | |||
| gitproject = GitlabProject.find_by_gitlab_project_id(temp[:gitprojectid]) | |||
| @repository.login = user.login | |||
| @repository.url = gitproject.localfile_url | |||
| @repository.root_url = gitproject.localfile_url | |||
| if request.post? && @repository.save | |||
| redirect_to settings_project_path(@project, :tab => 'repositories') | |||
| else | |||
| @@ -194,6 +252,13 @@ class RepositoriesController < ApplicationController | |||
| private :pickup_extra_info | |||
| def committers | |||
| @gitlab_project = GitlabProject.find_by_localfile_url(@repository.url) | |||
| if @gitlab_project | |||
| # gitlab项目,获取当前项目的gitabuser列表 | |||
| @gitlabusers = get_project_users(@gitlab_project.gitlab_project_id) | |||
| RepositoriesController.cur_gitlab_user= @gitlabusers | |||
| end | |||
| @committers = @repository.committers | |||
| @users = @project.users | |||
| additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) | |||
| @@ -208,6 +273,38 @@ class RepositoriesController < ApplicationController | |||
| end | |||
| end | |||
| # add by nwb | |||
| def self.cur_gitlab_user=(users) | |||
| Thread.current[:gitlab_user] = users | |||
| end | |||
| # add by nwb | |||
| def self.cur_gitlab_user | |||
| Thread.current[:gitlab_user] ||= nil | |||
| end | |||
| # add by nwb | |||
| # gitlab成员管理界面搜索处理 | |||
| def gitlabautocomplete | |||
| @gitlab_project = GitlabProject.find_by_gitlab_project_id(params[:gitlab_project_id]) | |||
| if @gitlab_project | |||
| # gitlab项目,获取当前项目的gitabuser列表 | |||
| # gitlab不支持ajax发送http请求数据 | |||
| #@gitlabusers = get_project_users(@gitlab_project.gitlab_project_id) | |||
| @gitlabusers = RepositoriesController.cur_gitlab_user | |||
| end | |||
| respond_to do |format| | |||
| format.js | |||
| end | |||
| end | |||
| # add by nwb | |||
| # 添加一个用户至gitlab项目 | |||
| def add_gitlab_user | |||
| dd | |||
| end | |||
| def destroy | |||
| @root_path=RepositoriesHelper::ROOT_PATH | |||
| @repo_name=User.current.login.to_s+"_"+@repository.identifier.to_s | |||
| @@ -217,15 +314,15 @@ class RepositoriesController < ApplicationController | |||
| redirect_to settings_project_path(@project, :tab => 'repositories') | |||
| if(@repository.type=="Repository::Git") | |||
| logger.info "destory the repository value"+"root path"+@root_path+"repo_name"+@repo_name+ | |||
| "repository_name"+@repository_name+"user group"+@middle | |||
| 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 | |||
| "repository_name"+@repository_name+"user group"+@middle | |||
| #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 | |||
| gitlabproject = GitlabProject.find_by_localfile_url(@repository.url) | |||
| if gitlabproject | |||
| gitlabproject.destroy | |||
| end | |||
| end | |||
| end | |||
| @@ -257,7 +354,7 @@ class RepositoriesController < ApplicationController | |||
| @course_tag = params[:course] | |||
| project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT | |||
| ip = RepositoriesHelper::REPO_IP_ADDRESS | |||
| @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ | |||
| @repos_url = @repository.repos_url#"http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ | |||
| @repository.url.slice(project_path_cut, @repository.url.length).to_s | |||
| if @course_tag == 1 | |||
| render :action => 'show', :layout => 'base_courses' | |||
| @@ -479,6 +479,15 @@ module ApplicationHelper | |||
| s.html_safe | |||
| end | |||
| #扩展的checkbox生成 | |||
| def principals_check_box_tags_style_ex(name, principals) | |||
| s = '' | |||
| principals.each do |principal| | |||
| s << "<label style=' display:block'>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal.userInfo }</label>\n" | |||
| end | |||
| s.html_safe | |||
| end | |||
| #扩展的checkbox生成 | |||
| def principals_radio_box_tags_ex(name, principals) | |||
| s = '' | |||
| @@ -7,13 +7,19 @@ | |||
| module GitlabHelper | |||
| # gitlab版本库数据本地保存的根目录 | |||
| ROOT_PATH="/home/git/repositories/" | |||
| 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" | |||
| #REPO_IP_ADDRESS = "http://" + Setting.gitlab_server | |||
| REPO_IP_ADDRESS = "http://192.168.1.200" | |||
| GITLAB_API = "/api/v3" | |||
| # gitlab的默认登录用户(需管理员) | |||
| LOGIN_USER = Setting.gitlab_login_user | |||
| # gitlab的默认登录密码 | |||
| LOGIN_PASSWORD = Setting.gitlab_login_password | |||
| # 新建用户的默认密码 | |||
| DEFAULT_PASSWOR="123456" | |||
| # 用户在项目中的权限级别 | |||
| GUEST = 10 | |||
| @@ -33,6 +39,12 @@ module GitlabHelper | |||
| Thread.current[:gitlab_token] ||= nil | |||
| end | |||
| def login_check | |||
| if GitlabHelper.gitlab_token.nil? | |||
| login_gitlab(LOGIN_USER,LOGIN_PASSWORD) | |||
| end | |||
| end | |||
| # 登录gitlab | |||
| # add by nwb | |||
| def login_gitlab(email,password) | |||
| @@ -41,6 +53,7 @@ module GitlabHelper | |||
| 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'] | |||
| @@ -49,13 +62,50 @@ module GitlabHelper | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| # 登录并初始化gitlab用户 | |||
| # 登录成功且本地未保存数据时保存 | |||
| # email:登录gitlab用户邮件,loginname:登录gitlab用户账号, password :登录gitlab用户密码 | |||
| # user_id:用户在trustie中的编号 | |||
| # add by nwb | |||
| def login_init_gitlab(email,password,loginname,user_id) | |||
| 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) | |||
| if temp['username'] == loginname | |||
| # 保存数据 | |||
| gituser = GitlabUser.new | |||
| gituser.user_id = user_id | |||
| gituser.gitlab_user_id = temp['id'] | |||
| gituser.email = email | |||
| gituser.password = password | |||
| gituser.login =loginname | |||
| gituser.save | |||
| return true | |||
| end | |||
| end | |||
| return false | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| # 创建项目 | |||
| # add by nwb | |||
| def create_project(project_name) | |||
| def create_project(project_name,project_id) | |||
| login_check | |||
| url = REPO_IP_ADDRESS + GITLAB_API + "/projects" | |||
| uri = URI.parse(url) | |||
| data = {name:project_name, private_token:GitlabHelper.gitlab_token} | |||
| @@ -64,50 +114,82 @@ module GitlabHelper | |||
| if res.code == '201' | |||
| temp = ActiveSupport::JSON.decode(res.body) | |||
| #新创建项目的版本库地址 | |||
| respo = temp['http_url_to_repo'] | |||
| respo['http://localhost'] = REPO_IP_ADDRESS | |||
| repository_url = String.new(temp['http_url_to_repo']) | |||
| repository_url['http://localhost'] = REPO_IP_ADDRESS | |||
| # 新创建项目的web地址 | |||
| webaddress = temp['web_url'] | |||
| webaddress['http://localhost'] = REPO_IP_ADDRESS | |||
| web_url = String.new(temp['web_url']) | |||
| web_url['http://localhost'] = REPO_IP_ADDRESS | |||
| # 新创建项目的本地文件路径 | |||
| localfile = String.new(temp['web_url']) | |||
| localfile[REPO_IP_ADDRESS] = ROOT_PATH | |||
| # 保存数据 | |||
| gitproject =GitlabProject.new | |||
| gitproject.project_id = project_id | |||
| gitproject.gitlab_project_id = temp['id'] | |||
| gitproject.repository_url = repository_url | |||
| gitproject.web_url = web_url | |||
| gitproject.localfile_url = localfile | |||
| gitproject.save | |||
| return true | |||
| else | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| # 为指定用户创建版本库 | |||
| # project_name:版本库名称 user_id:Gitlab版本库中的用户编号 | |||
| # project_id: 项目在trustie中的编号 | |||
| # add by nwb | |||
| def create_project_for_user(project_name,user_id) | |||
| url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id | |||
| def create_project_for_user(project_name,project_id,user_id) | |||
| login_check | |||
| url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id.to_s | |||
| uri = URI.parse(url) | |||
| data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token} | |||
| tempResult = Hash.new | |||
| 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 | |||
| repository_url = String.new(temp['http_url_to_repo']) | |||
| repository_url['http://localhost'] = REPO_IP_ADDRESS | |||
| # 新创建项目的web地址 | |||
| webaddress = temp['web_url'] | |||
| webaddress['http://localhost'] = REPO_IP_ADDRESS | |||
| return true | |||
| web_url = String.new(temp['web_url']) | |||
| web_url['http://localhost'] = REPO_IP_ADDRESS | |||
| # 新创建项目的本地文件路径 | |||
| localfile = String.new(temp['web_url']) | |||
| localfile['http://localhost'] = ROOT_PATH | |||
| # 保存数据 | |||
| gitproject = GitlabProject.new | |||
| gitproject.project_id = project_id | |||
| gitproject.gitlab_project_id = temp['id'] | |||
| gitproject.repository_url = repository_url | |||
| gitproject.web_url = web_url | |||
| gitproject.localfile_url = localfile | |||
| gitproject.save | |||
| tempResult[:result]= true | |||
| tempResult[:gitprojectid]=gitproject.gitlab_project_id | |||
| else | |||
| return false | |||
| tempResult[:result]= false | |||
| end | |||
| rescue =>err | |||
| return false | |||
| logger.error "gitlab: error: #{err.message}" | |||
| tempResult[:result]= false | |||
| end | |||
| tempResult | |||
| end | |||
| # 创建用户 | |||
| # loginname:登录名称(版本库路径包含) name:用户姓名 | |||
| # add by nwb | |||
| def create_user (loginname,name,password,email) | |||
| def create_user (loginname,name,password,email,userid) | |||
| login_check | |||
| 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} | |||
| @@ -116,12 +198,22 @@ module GitlabHelper | |||
| if res.code == '201' | |||
| temp = ActiveSupport::JSON.decode(res.body) | |||
| #新创建的gitlab用户编号(需保存) | |||
| user_id = temp['id'] | |||
| git_user_id = temp['id'] | |||
| # 保存数据 | |||
| gituser = GitlabUser.new | |||
| gituser.user_id = userid | |||
| gituser.gitlab_user_id = git_user_id | |||
| gituser.email = email | |||
| gituser.password = password | |||
| gituser.login =loginname | |||
| gituser.save | |||
| return true | |||
| else | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| @@ -130,6 +222,7 @@ module GitlabHelper | |||
| # user_id:用户在gitlab中的id | |||
| # add by nwb | |||
| def delete_user(user_id) | |||
| login_check | |||
| url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id | |||
| uri = URI.parse(url) | |||
| data = {id:user_id,private_token:GitlabHelper.gitlab_token} | |||
| @@ -140,16 +233,60 @@ module GitlabHelper | |||
| res= http.start { |http| http.request req } | |||
| if res.code == '200' | |||
| temp = ActiveSupport::JSON.decode(res.body) | |||
| # 删除成功,对应更新trustie用户的gitlab用户编号 | |||
| # 删除成功,更新数据 | |||
| gituser = GitlabUser.find_by_gitlab_user_id(user_id_) | |||
| gituser.destroy | |||
| return true | |||
| else | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| # 获取指定gitlab项目用户列表 | |||
| # project_id:gitlab项目编号 | |||
| # add by nwb | |||
| def get_project_users(project_id) | |||
| login_check | |||
| url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id.to_s + "/members" | |||
| uri = URI.parse(url) | |||
| data = {id:project_id, private_token:GitlabHelper.gitlab_token} | |||
| uri.query = URI.encode_www_form(params) | |||
| http = Net::HTTP.new uri.host, uri.port | |||
| #https协议额外解析 | |||
| 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.form_data = data | |||
| res = http.start { |http| http.request request } | |||
| if res.code == '200' | |||
| temp = ActiveSupport::JSON.decode(res.body) | |||
| # 取gitlabuser集合 | |||
| gitlabusers = [] | |||
| temp.each do |gituser| | |||
| gituser_id = gituser['id'] | |||
| gitlabuser = GitlabUser.find_by_gitlab_user_id(gituser_id) | |||
| if gitlabuser | |||
| gitlabuser.project_role_set(project_id, gituser['access_level']) | |||
| gitlabusers << gitlabuser | |||
| end | |||
| end | |||
| return gitlabusers | |||
| else | |||
| return nil | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return nil | |||
| end | |||
| end | |||
| # 给用户添加一个可操作的项目 | |||
| # 若用户已在该项目中,权限级别取新权限与现有权限的最大值 | |||
| # project_id:项目在gitlab中的id user_id:用户在gitlab中的id | |||
| @@ -160,6 +297,7 @@ module GitlabHelper | |||
| #MASTER = 40 | |||
| # add by nwb | |||
| def add_user_to_project(project_id,user_id,access_level) | |||
| login_check | |||
| 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} | |||
| @@ -172,14 +310,85 @@ module GitlabHelper | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| # 将trustie用户添加进指定trustie项目的所有gitlab项目 | |||
| # project_id:trustie项目id user_id:用户在trustie中的id | |||
| def add_trustie_user(project_id,user_id) | |||
| respos = Repository.find_all_by_project_id(project_id) | |||
| respos.each do |respo| | |||
| # 循环删除所有版本库 | |||
| add_trustie_user_to_repos(user_id,respo.url) | |||
| end | |||
| end | |||
| # 将trustie用户添加进gitlab版本库 | |||
| # user_id:用户在trustie中的id local_file_url:gitlab版本库的本地路径 | |||
| def add_trustie_user_to_repos(user_id,local_file_url) | |||
| # 找对应的Gitlab项目 | |||
| gitlab_project = GitlabProject.find_by_localfile_url(local_file_url) | |||
| if gitlab_project.nil? | |||
| return false | |||
| end | |||
| # 找对应的Gitlab用户,不存在则创建 | |||
| user = User.find(user_id) | |||
| gitlab_user = GitlabUser.find_by_user_id(user_id) | |||
| if gitlab_user.nil? | |||
| if !create_user(user.login,user.show_name,DEFAULT_PASSWOR,user.mail,user.id) | |||
| # 创建gitlab用户失败 | |||
| # 验证gitlab是否可由指定的账号、密码登录 | |||
| if login_init_gitlab(user.mail,DEFAULT_PASSWOR,user.login,user.id) | |||
| gitlab_user = GitlabUser.find_by_user_id(user.id) | |||
| else | |||
| flash[:error] = l(:error_create_gitlab_user) | |||
| return false | |||
| end | |||
| end | |||
| gitlab_user = GitlabUser.find_by_user_id(user.id) | |||
| end | |||
| access_level = DEVELOPER | |||
| add_user_to_project(gitlab_project.gitlab_project_id,gitlab_user.gitlab_user_id,access_level) | |||
| end | |||
| # 将trustie用户从指定trustie项目的所有gitlab项目中移除 | |||
| # project_id:trustie项目id user_id:用户在trustie中的id | |||
| def delete_trustie_user(project_id,user_id) | |||
| respos = Repository.find_all_by_project_id(project_id) | |||
| respos.each do |respo| | |||
| # 循环删除所有版本库 | |||
| delete_trustie_user_from_repos(user_id,respo.url) | |||
| end | |||
| end | |||
| # 将trustie用户从gitlab版本库移除 | |||
| # user_id:用户在trustie中的id local_file_url:gitlab版本库的本地路径 | |||
| def delete_trustie_user_from_repos(user_id,local_file_url) | |||
| # 找对应的Gitlab项目 | |||
| gitlab_project = GitlabProject.find_by_localfile_url(local_file_url) | |||
| if gitlab_project.nil? | |||
| return false | |||
| end | |||
| # 找对应的Gitlab用户,不存在则创建 | |||
| user = User.find(user_id) | |||
| gitlab_user = GitlabUser.find_by_user_id(user_id) | |||
| if gitlab_user.nil? | |||
| return false | |||
| end | |||
| delete_user_from_project(gitlab_project.gitlab_project_id,gitlab_user.gitlab_user_id) | |||
| gitlab_user.destroy | |||
| end | |||
| # 从项目中删除用户 | |||
| # project_id:项目在gitlab中的ids user_id:用户在gitlab中的id | |||
| # add by nwb | |||
| def delete_user_from_project(project_id,user_id) | |||
| login_check | |||
| 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} | |||
| @@ -195,6 +404,7 @@ module GitlabHelper | |||
| return false | |||
| end | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return false | |||
| end | |||
| end | |||
| @@ -218,6 +428,7 @@ module GitlabHelper | |||
| response = http.start { |http| http.request(request) } | |||
| return JSON.parse response.body | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return nil | |||
| end | |||
| end | |||
| @@ -228,6 +439,7 @@ module GitlabHelper | |||
| uri = URI.parse(url) | |||
| uri.query = URI.encode_www_form(params) | |||
| http = Net::HTTP.new uri.host, uri.port | |||
| #https协议额外解析 | |||
| if uri.scheme == 'https' | |||
| http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |||
| http.use_ssl = true | |||
| @@ -240,6 +452,7 @@ module GitlabHelper | |||
| response = http.start { |http| http.request request } | |||
| return JSON.parse response.body | |||
| rescue =>err | |||
| logger.error "gitlab: error: #{err.message}" | |||
| return nil | |||
| end | |||
| end | |||
| @@ -50,6 +50,33 @@ module MembersHelper | |||
| s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') | |||
| end | |||
| # add by nwb | |||
| def render_principals_for_gitlab(project,gitlabusers,gitlab_project) | |||
| idlist = "(" | |||
| count = gitlabusers.count | |||
| for i in 0...count | |||
| gitlabuser = gitlabusers[i] | |||
| idlist+="'" + gitlabuser.user_id.to_s + "'" | |||
| if i != count-1 | |||
| idlist+="," | |||
| end | |||
| end | |||
| idlist += ")" | |||
| scope = Principal.active.where('users.id not in' + idlist).sorted.member_of(project).like(params[:q]) | |||
| principal_count = scope.count | |||
| principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young | |||
| principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all | |||
| s = content_tag('div', principals_check_box_tags_style_ex('membership[user_ids][]', principals), :id => 'principals') | |||
| links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| | |||
| link_to text, gitlabautocomplete_project_repositories_path(project, parameters.merge(:q => params[:q],:gitlab_prject_id=>gitlab_project.project_id, :format => 'js')), :remote => true | |||
| } | |||
| s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') | |||
| end | |||
| # 当前申请加入的成员名单 | |||
| def render_principals_for_applied_members(project) | |||
| @@ -46,6 +46,33 @@ module RepositoriesHelper | |||
| end | |||
| end | |||
| # 项目成员列表 | |||
| def render_principals_for_project(project,gitlabusers,gitlab_project) | |||
| idlist = "(" | |||
| count = gitlabusers.count | |||
| for i in 0...count | |||
| gitlabuser = gitlabusers[i] | |||
| idlist+="'" + gitlabuser.user_id.to_s + "'" | |||
| if i != count-1 | |||
| idlist+="," | |||
| end | |||
| end | |||
| idlist += ")" | |||
| scope = Principal.active.where('users.id not in' + idlist).sorted.member_of(project).like(params[:q]) | |||
| principal_count = scope.count | |||
| principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young | |||
| principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all | |||
| s = content_tag('div', principals_check_box_tags_style_ex('membership[user_ids][]', principals), :id => 'principals') | |||
| links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| | |||
| link_to text, gitlabautocomplete_project_repositories_path(project, parameters.merge(:q => params[:q],:gitlab_prject_id=>gitlab_project.project_id, :format => 'js')), :remote => true | |||
| } | |||
| s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') | |||
| end | |||
| def render_changeset_changes | |||
| changes = @changeset.filechanges.limit(1000).reorder('path').all.collect do |change| | |||
| case change.action | |||
| @@ -0,0 +1,5 @@ | |||
| class GitlabProject < ActiveRecord::Base | |||
| attr_accessible :project_id | |||
| validates_uniqueness_of :localfile_url | |||
| end | |||
| @@ -0,0 +1,19 @@ | |||
| class GitlabUser < ActiveRecord::Base | |||
| attr_accessible :user_id | |||
| belongs_to :user | |||
| # 获取用户在Gitlab项目中的角色 | |||
| def project_role gitlab_project_id | |||
| @project_role[gitlab_project_id] | |||
| end | |||
| def project_role_set(gitlab_project_id,role) | |||
| if @project_role.nil? | |||
| @project_role = [] | |||
| end | |||
| @project_role[gitlab_project_id] = role | |||
| end | |||
| validates_uniqueness_of :gitlab_user_id | |||
| end | |||
| @@ -135,6 +135,37 @@ class Repository < ActiveRecord::Base | |||
| end | |||
| end | |||
| # 获取版本库地址 | |||
| def repos_url | |||
| if self.scm_name=="Git" | |||
| gitlabproject = GitlabProject.find_by_localfile_url(self.url) | |||
| if gitlabproject.nil? | |||
| # 兼容老git模式 | |||
| ip = Setting.gitlab_server | |||
| if ip.nil? | |||
| self.url | |||
| else | |||
| project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT | |||
| "http://" + self.login.to_s + self.identifier.to_s + ip + self.url.slice(project_path_cut, self.url.length) | |||
| end | |||
| else | |||
| gitlabproject.repository_url | |||
| end | |||
| else | |||
| self.url | |||
| end | |||
| end | |||
| # 版本库的web管理地址 | |||
| def web_url | |||
| gitlabproject = GitlabProject.find_by_localfile_url(self.url) | |||
| if gitlabproject | |||
| gitlabproject.web_url | |||
| else | |||
| '' | |||
| end | |||
| end | |||
| def <=>(repository) | |||
| if is_default? | |||
| -1 | |||
| @@ -0,0 +1,3 @@ | |||
| <% if @gitlabusers%> | |||
| $('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_gitlab(@project,@gitlabusers,@gitlab_project)) %>'); | |||
| <%end%> | |||
| @@ -7,8 +7,8 @@ | |||
| <th><%= l(:field_identifier) %></th> | |||
| <th><%= l(:field_repository_is_default) %></th> | |||
| <th><%= l(:label_scm) %></th> | |||
| <th><%= l(:label_repository_path) %></th> | |||
| <th></th> | |||
| <th style="width:250px"><%= l(:label_repository_path) %></th> | |||
| <th style="width:250px"><%= l(:label_web_path) %></th> | |||
| </tr> | |||
| </thead> | |||
| <tbody> | |||
| @@ -20,34 +20,33 @@ | |||
| </td> | |||
| <td align="center"><%= checked_image repository.is_default? %></td> | |||
| <td><%=h repository.scm_name %></td> | |||
| <%if repository.scm_name=="Git"%> | |||
| <td>http://<%= repository.login.to_s %>_<%= repository.identifier.to_s%>@<%= ip %><%=h repository.url.slice(project_path_cut, repository.url.length) %></td><!--Modified by tanxianbo--> | |||
| <%else %> | |||
| <td><%=h repository.url %></td> | |||
| <% end %> | |||
| <td class="buttons" style="text-align:left"> | |||
| <td><%=h repository.repos_url %></td> | |||
| <td><%=h repository.web_url %></td> | |||
| </tr> | |||
| <tr> | |||
| <td></td> <td></td><td></td><td></td> | |||
| <td class="buttons" style="width:250px"> | |||
| <% if repository.scm_name=="Subversion"%> | |||
| <%if User.current.allowed_to?(:manage_repository, @project) %> | |||
| <%= link_to(l(:label_user_plural), committers_repository_path(repository), | |||
| :class => 'icon icon-user') %> | |||
| :class => 'icon icon-user') %> | |||
| <%= link_to(l(:button_edit), edit_repository_path(repository), | |||
| :class => 'icon icon-edit') %> | |||
| <%= delete_link repository_path(repository) %> | |||
| <% end %> | |||
| <% elsif repository.scm_name=="Git"%> | |||
| <%if User.current.allowed_to?(:manage_repository, @project) %> | |||
| <!-- <%= link_to(l(:button_edit), edit_repository_path(repository), | |||
| :class => 'icon icon-edit') %> --> | |||
| <%= link_to(l(:label_user_plural), committers_repository_path(repository), | |||
| :class => 'icon icon-user') %> | |||
| <% if repository.login.to_s==User.current.login.to_s %> | |||
| <%= delete_link repository_path(repository) %> | |||
| <% end %> | |||
| <%= link_to(l(:label_user_plural), committers_repository_path(repository),:class => 'icon icon-user') %> | |||
| <%= link_to(l(:button_edit), edit_repository_path(repository),:class => 'icon icon-edit') %> | |||
| <%# if repository.login.to_s==User.current.login.to_s %> | |||
| <%= delete_link repository_path(repository) %> | |||
| <%#= link_to l(:button_delete), repository_path(repository), :method => :delete,:data => {:confirm => l(:label_are_you_sure)},:class => 'icon icon-del'%> | |||
| <%# end %> | |||
| <% end %> | |||
| <% end %> | |||
| </td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| @@ -3,11 +3,16 @@ | |||
| <div class="box tabular"> | |||
| <p> | |||
| <%= label_tag('repository_scm', l(:label_scm)) %> | |||
| <!--Modified by tanxianbo--> | |||
| <%= select_tag('repository_scm', | |||
| options_for_select(["Subversion"],@repository.class.name.demodulize), | |||
| :data => {:remote => true, :method => 'get'})%> | |||
| <!--Ended by tanxianbo--> | |||
| <% if @repository.identifier_frozen? %> | |||
| <%= select_tag('repository_scm', | |||
| options_for_select([@repository.class.name.demodulize],@repository.class.name.demodulize), | |||
| :data => {:remote => true, :method => 'get'})%> | |||
| <% else %> | |||
| <%= select_tag('repository_scm', | |||
| options_for_select(["Subversion"],@repository.class.name.demodulize), | |||
| :data => {:remote => true, :method => 'get'})%> | |||
| <% end %> | |||
| </p> | |||
| <p><%= f.check_box :is_default, :label => :field_repository_is_default %></p> | |||
| @@ -20,10 +25,10 @@ | |||
| <p><%= f.text_field :url, :size => 60, :required => true, :disabled => !@repository.safe_attribute?('url') %> | |||
| <em class='info'><%= "#{l(:label_exist_repository_path)}" %></em> | |||
| </p> | |||
| <p><%= f.text_field :login, :size => 30 %></p> | |||
| <p><%= f.text_field :login, :size => 30 , :disabled => @repository.identifier_frozen? %></p> | |||
| <p><%= f.password_field :password, :size => 30, :name => 'ignore', :value => ((@repository.new_record? || @repository.password.blank?) ? '' : ('x'*15)), | |||
| :onfocus => "this.value=''; this.name='repository[password]';", | |||
| :onchange => "this.name='repository[password]';" %></p> | |||
| :onchange => "this.name='repository[password]';", :disabled => @repository.identifier_frozen? %></p> | |||
| </div> | |||
| <!--Ended by tanxianbo--> | |||
| <p> | |||
| @@ -12,11 +12,10 @@ border:none | |||
| <p> | |||
| <%= label_tag('repository_scm', l(:label_scm)) %> | |||
| <!--Modified by tanxianbo--> | |||
| <%= select_tag('repository_scm', | |||
| options_for_select(["Git"],@repository.class.name.demodulize), | |||
| :data => {:remote => true, :method => 'get'})%> | |||
| <!--Ended by tanxianbo--> | |||
| <%= select_tag('repository_scm', | |||
| options_for_select(["Git"], @repository.class.name.demodulize), | |||
| :data => {:remote => true, :method => 'get'}) %> | |||
| <% if @repository && ! @repository.class.scm_available %> | |||
| <em class="info error"><%= l(:text_scm_command_not_available) %></em> | |||
| <% end %> | |||
| @@ -28,8 +27,27 @@ border:none | |||
| <%= l(:text_repository_identifier_info).html_safe %></em> | |||
| <% end %></p> | |||
| <!-- <p><%= f.text_field :url, :size => 60, :required => true,:readonly=>true, :class=>'textbg'%></p> --> | |||
| <p><%= f.password_field :upassword, :required =>true, :label=> :field_password %> | |||
| <em class="info"><%= l(:label_upassword_info)%></em></p> | |||
| <% if @gitlab_user %> | |||
| <p><%= f.text_field :gitlab_user, :required => true, :label => :field_account, :value => @gitlab_user.login, :disabled =>true %> | |||
| <em class="info"><%= l(:label_gitlab_account) %></em></p> | |||
| <p><%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => @gitlab_user.email, :disabled =>true %> | |||
| <em class="info"><%= l(:label_gitlab_email) %></em></p> | |||
| <p><%= f.password_field :upassword, :required => true, :label => :field_password, :value => @gitlab_user.password, :disabled =>true %> | |||
| <em class="info"><%= l(:label_gitlab_password) %></em></p> | |||
| <% else %> | |||
| <p><%= f.text_field :gitlab_user, :required => true, :label => :field_account, :value => User.current.login %> | |||
| <em class="info"><%= l(:label_gitlab_account) %></em></p> | |||
| <p><%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => User.current.mail %> | |||
| <em class="info"><%= l(:label_gitlab_email) %></em></p> | |||
| <p><%= f.password_field :upassword, :required => true, :label => :field_password %> | |||
| <em class="info"><%= l(:label_gitlab_password) %></em></p> | |||
| <% end %> | |||
| </div> | |||
| <p> | |||
| <%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save)) %> | |||
| @@ -0,0 +1,117 @@ | |||
| <%= error_messages_for 'member' %> | |||
| <% | |||
| roles = Hash.new | |||
| roles[:Guest] = GitlabHelper::GUEST | |||
| roles[:Reporter] = GitlabHelper::REPORTER | |||
| roles[:Developer] = GitlabHelper::DEVELOPER | |||
| roles[:Master] = GitlabHelper::MASTER | |||
| # gitlab用户角色的字符描述 | |||
| roles_str = Hash.new | |||
| roles_str[GitlabHelper::GUEST] = 'Guest' | |||
| roles_str[GitlabHelper::REPORTER] = 'Reporter' | |||
| roles_str[GitlabHelper::DEVELOPER] = 'Developer' | |||
| roles_str[GitlabHelper::MASTER] ='Master' | |||
| members = @gitlabusers | |||
| if members.nil? | |||
| members = [] | |||
| end | |||
| %> | |||
| <!--项目的gitlab成员列表--> | |||
| <div id="project_gitlab_user_div"> | |||
| <table> | |||
| <tr> | |||
| <td style="width: 50%;vertical-align:top;text-align:left;"> | |||
| <div class="splitcontentleft1"> | |||
| <% if members.any? %> | |||
| <table class="list members1"> | |||
| <thead> | |||
| <tr> | |||
| <th><%= l(:label_user) %></th> | |||
| <th><%= l(:label_role_plural) %></th> | |||
| <th style="width:15%"></th> | |||
| <%= call_hook(:view_projects_settings_members_table_header, :project => @project) %> | |||
| </tr> | |||
| </thead> | |||
| <tbody> | |||
| <% members.each do |member| %> | |||
| <%# next if member.user.id == @project.user_id%> | |||
| <tr id="git-member-<%= member.id %>" class="<%= cycle 'odd', 'even' %> member"> | |||
| <td class="<%= member.user.class.name.downcase %>"><%= link_to_user member.user %></td> | |||
| <td class="roles"> | |||
| <span id="git-member-<%= member.id %>-roles"> | |||
| <% if !member.project_role(@gitlab_project.gitlab_project_id).nil?%> | |||
| <%= h roles_str[member.project_role(@gitlab_project.gitlab_project_id)] %> | |||
| <%end%> | |||
| </span> | |||
| <%= form_for(member, {:as => :membership, :remote => true, :url => membership_path(member), | |||
| :method => :put, | |||
| :html => {:id => "git-member-#{member.id}-roles-form", :class => 'hol'}} | |||
| ) do |f| %> | |||
| <p> | |||
| <% roles.each do |role| %> | |||
| <label><%= radio_button_tag 'gitlab[role_ids][]', role[1] %> <%= h role[0] %></label><br/> | |||
| <% end %></p> | |||
| <p><%= submit_tag l(:button_change), :class => "small" %> | |||
| <%= link_to_function l(:button_cancel), | |||
| "$('#git-member-#{member.id}-roles').show(); $('#git-member-#{member.id}-roles-form').hide(); return false;" | |||
| %></p> | |||
| <% end %> | |||
| </td> | |||
| <% if member.user.id == @project.user_id %> | |||
| <td class="buttons"></td> | |||
| <% else %> | |||
| <td class="buttons"> | |||
| <%= link_to_function l(:button_edit), | |||
| "$('#git-member-#{member.id}-roles').hide(); $('#git-member-#{member.id}-roles-form').show(); return false;", | |||
| :class => 'icon icon-edit' %> | |||
| <%= delete_link membership_path(member), | |||
| :remote => true, | |||
| :data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {}) if member.deletable? %> | |||
| </td> | |||
| <% end %> | |||
| <%= call_hook(:view_projects_settings_members_table_row, {:project => @project, :member => member}) %> | |||
| </tr> | |||
| <% end; reset_cycle %> | |||
| </tbody> | |||
| </table> | |||
| <% else %> | |||
| <p class="nodata"><%= l(:label_no_data) %></p> | |||
| <% end %> | |||
| </div> | |||
| </td> | |||
| <td style="width: 50%;vertical-align:top;text-align:left;"> | |||
| <div class="splitcontentright1"> | |||
| <% if roles.any? %> | |||
| <%= form_for(@member, {:as => :add_gitlab_user, :url => add_gitlab_user_project_repositories_path(@project), :remote => true, :method => :post}) do |f| %> | |||
| <fieldset> | |||
| <legend><%= l(:label_member_new) %></legend> | |||
| <p><%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %></p> | |||
| <%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript gitlabautocomplete_project_repositories_path(@project,:gitlab_project_id=>@gitlab_project.gitlab_project_id, :format => 'js') }')" %> | |||
| <div id="principals_for_new_member"> | |||
| <%= render_principals_for_project(@project,@gitlabusers,@gitlab_project) %> | |||
| </div> | |||
| <p style="padding-top: 5px"><%= l(:label_role_plural) %>: | |||
| <% roles.each do |role| %> | |||
| <label style=" display:block;height: 5px"><%= radio_button_tag 'gitlab[role_ids][]', role[1] %> <%= h role[0] %></label><br/> | |||
| <% end %></p> | |||
| <%= hidden_field_tag "gitlab_project_id", "#{@gitlab_project.gitlab_project_id}" %> | |||
| <p><%= submit_tag l(:button_add), :id => 'git-member-add-submit' %></p> | |||
| </fieldset> | |||
| <% end %> | |||
| <% end %> | |||
| </div> | |||
| </td> | |||
| </tr> | |||
| </table> | |||
| </div> | |||
| @@ -2,6 +2,23 @@ | |||
| <%= simple_format(l(:text_repository_usernames_mapping)) %> | |||
| <!--新增gitlab用户界面 by nwb--> | |||
| <% if User.current.logged? && User.current.allowed_to?(:add_gitlab_user, @project)%> | |||
| <div class="borad-setitle"> | |||
| <%= link_to l(:label_gitlab_user_manage), | |||
| "javascript:void(0);", | |||
| :class => 'icon icon-edit', | |||
| :onclick => "$('#gitlab-user-manager').show(); return false;" if User.current.logged? %> | |||
| </div> | |||
| <div id="gitlab-user-manager" class="add_frame" style="display:none;"> | |||
| <%= render :partial => 'gitlab_user_manage' %> | |||
| <p><%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %> | |||
| <%= link_to l(:button_cancel), "#", :onclick => '$("#gitlab-user-manager").hide(); return false;', :class => 'whiteButton m3p10' %></p> | |||
| <div id="preview" class="wiki"></div> | |||
| </div> | |||
| <% end %> | |||
| <% if @committers.empty? %> | |||
| <p class="nodata"><%= l(:label_no_data) %></p> | |||
| <% else %> | |||
| @@ -0,0 +1,3 @@ | |||
| <% if @gitlabusers%> | |||
| $('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_gitlab(@project,@gitlabusers,@gitlab_project)) %>'); | |||
| <%end%> | |||
| @@ -205,6 +205,7 @@ default: | |||
| # that overrides the default ones | |||
| production: | |||
| # specific configuration options for development environment | |||
| # that overrides the default ones | |||
| development: | |||
| @@ -132,6 +132,7 @@ en: | |||
| actionview_instancetag_blank_option: Please select | |||
| blank: "can't be blank" | |||
| attachment_all: "All" | |||
| attachment_browse: "Attachment Content Browse" | |||
| attachment_sufix_browse: "Attachment Type Browse" | |||
| @@ -186,6 +187,9 @@ en: | |||
| notice_account_deleted: "Your account has been permanently deleted." | |||
| notice_user_successful_create: "User %{id} created." | |||
| error_create_gitlab_user: "Create Gitlab user failed." | |||
| error_create_gitlab_project: "Create Gitlab project failed." | |||
| error_class_period_only_num: "class period can only digital" | |||
| error_can_t_load_default_data: "Default configuration could not be loaded: %{value}" | |||
| error_scm_not_found: "The entry or revision was not found in the repository." | |||
| @@ -1344,6 +1348,7 @@ en: | |||
| label_join: join Trustie! | |||
| label_repository_new: link to existing SVN repository | |||
| label_repository_path: path of repository | |||
| label_web_path: web management path | |||
| label_repository_new_repos: create a new repository | |||
| label_repository_no: have no repository? | |||
| label_welcome_page_to: Participate %{project_count} projects! | |||
| @@ -1363,6 +1368,11 @@ en: | |||
| label_all_revisions: All revisions: | |||
| label_repository_name: Repository name | |||
| label_upassword_info: The password can be shared in the group | |||
| label_gitlab_email: The email user to login gitlab | |||
| label_gitlab_account: The account user to login gitlab | |||
| label_gitlab_password: The password user to login gitlab | |||
| label_gitlab_user_manage: Gitlab user manage | |||
| label_are_you_sure: Are you sure? | |||
| label_how_commit_code: How to commit code: | |||
| label_how_commit_code_chinese: Chinese | |||
| label_welcome_leave_message: Hi!The platform is currently in beta version.If you have any comments and suggestions, please | |||
| @@ -196,6 +196,10 @@ zh: | |||
| error_complete_occupation: "请您填写工作单位,否则本系统的部分功能将无法正常使用。" | |||
| error_create_gitlab_user: "创建Gitlab用户失败!可能已存在指定的用户名或邮件名。" | |||
| error_create_gitlab_project: "创建Gitlab项目失败!指定用户可能已拥有指定的Gitlab项目。" | |||
| blank: "不能为空字符" | |||
| error_class_period_only_num: "课程学时只能为数字" | |||
| error_can_t_load_default_data: "无法载入默认设置:%{value}" | |||
| error_scm_not_found: "版本库中不存在该条目和(或)其修订版本。" | |||
| @@ -1544,6 +1548,8 @@ zh: | |||
| label_board_description: 七嘴八舌,汇聚众人智慧,为您排忧解难! | |||
| label_create_course_description: 课程小社区,创建新课程,让我们共同分享多到想不到的公共资源! | |||
| label_welcome_page_to: 参与了 %{project_count} 个项目! | |||
| label_repository_path: 版本库路径 | |||
| label_web_path: Web管理路径 | |||
| label_repository_path_not_null: 库路径 不能为空字符 | |||
| label_password_not_null: 密码不能设置为空。 | |||
| label_exist_repository_path: 定义已有版本库URL路径,定义格式file:///, http://, https://, svn:// | |||
| @@ -1563,6 +1569,11 @@ zh: | |||
| label_have_message : 》有新的留言 | |||
| label_all_revisions: 所有版本: | |||
| label_upassword_info: 该密码在项目组内可共享 | |||
| label_gitlab_account: 用户登录Gitlab的账号,推荐使用当前用户。注意:若当前用户已创建过版本库,则会使用老账号 | |||
| label_gitlab_email: 用户登录Gitlab的邮件,推荐使用当前用户邮件 | |||
| label_gitlab_password: 用户登录Gitlab的密码,推荐使用当前用户密码。注意:若当前用户已创建过版本库,则会使用老密码 | |||
| label_gitlab_user_manage: Gitlab用户管理 | |||
| label_are_you_sure: 您确定要删除版本库吗?如果这是系统创建的Git库,将同时删除所有版本数据。 | |||
| label_how_commit_code: 查看如何提交代码: | |||
| label_how_commit_code_chinese: 中文 | |||
| # modified by bai | |||
| @@ -381,6 +381,10 @@ RedmineApp::Application.routes.draw do | |||
| member do | |||
| match 'committers', :via => [:get, :post] | |||
| end | |||
| collection do | |||
| get 'gitlabautocomplete' | |||
| match "add_gitlab_user" , via: [:get, :post] | |||
| end | |||
| end | |||
| resources :repositories, :except => [:index, :show] do | |||
| member do | |||
| @@ -117,6 +117,13 @@ commit_logtime_enabled: | |||
| commit_logtime_activity_id: | |||
| format: int | |||
| default: 0 | |||
| gitlab_server: | |||
| default: repository.trustie.net | |||
| gitlab_login_user: | |||
| default: admin@local.host | |||
| gitlab_login_password: | |||
| default: 123456 | |||
| # autologin duration in days | |||
| # 0 means autologin is disabled | |||
| autologin: | |||
| @@ -0,0 +1,16 @@ | |||
| class CreateGitlabProjects < ActiveRecord::Migration | |||
| def change | |||
| create_table :gitlab_projects do |t| | |||
| t.integer :gitlab_project_id | |||
| t.integer :project_id | |||
| #版本库地址 | |||
| t.string :repository_url | |||
| #版本库web地址 | |||
| t.string :web_url | |||
| #版本库本地地址 | |||
| t.string :localfile_url | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,17 @@ | |||
| class CreateGitlabUsers < ActiveRecord::Migration | |||
| def change | |||
| create_table :gitlab_users do |t| | |||
| # 用户在gitlab中的编号 | |||
| t.integer :gitlab_user_id | |||
| # 用户在trustie中的编号 | |||
| t.integer :user_id | |||
| # 登录gitlab所用的邮箱 | |||
| t.string :email | |||
| # 登录gitlab所用的密码 | |||
| t.string :password | |||
| # 登录gitlab所用的账号 | |||
| t.string :login | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,23 @@ | |||
| # -*coding:utf-8 -*- | |||
| class AddGitlabRights < ActiveRecord::Migration | |||
| def up | |||
| # 添加Gitlab权限 | |||
| Role.all.each do |role| | |||
| if role.name == 'Manager' | |||
| role.permissions.append(:add_gitlab_user ) | |||
| elsif role.name =='Developer' | |||
| role.permissions.append(:add_gitlab_user ) | |||
| elsif role.name == 'Reporter' | |||
| elsif role.name == '助教' | |||
| role.permissions.append(:add_gitlab_user ) | |||
| elsif role.name == '老师' | |||
| role.permissions.append(:add_gitlab_user ) | |||
| elsif role.name == '学生' | |||
| end | |||
| role.save() | |||
| end | |||
| end | |||
| def down | |||
| end | |||
| end | |||
| @@ -11,7 +11,7 @@ | |||
| # | |||
| # It's strongly recommended to check this file into your version control system. | |||
| ActiveRecord::Schema.define(:version => 20140722024513) do | |||
| ActiveRecord::Schema.define(:version => 20140725034309) do | |||
| create_table "activities", :force => true do |t| | |||
| t.integer "act_id", :null => false | |||
| @@ -429,6 +429,26 @@ ActiveRecord::Schema.define(:version => 20140722024513) do | |||
| t.datetime "updated_at", :null => false | |||
| end | |||
| create_table "gitlab_projects", :force => true do |t| | |||
| t.integer "gitlab_project_id" | |||
| t.integer "project_id" | |||
| t.string "repository_url" | |||
| t.string "web_url" | |||
| t.string "localfile_url" | |||
| t.datetime "created_at", :null => false | |||
| t.datetime "updated_at", :null => false | |||
| end | |||
| create_table "gitlab_users", :force => true do |t| | |||
| t.integer "gitlab_user_id" | |||
| t.integer "user_id" | |||
| t.string "email" | |||
| t.string "password" | |||
| t.string "login", :null => false | |||
| t.datetime "created_at", :null => false | |||
| t.datetime "updated_at", :null => false | |||
| end | |||
| create_table "groups_users", :id => false, :force => true do |t| | |||
| t.integer "group_id", :null => false | |||
| t.integer "user_id", :null => false | |||
| @@ -844,19 +864,6 @@ ActiveRecord::Schema.define(:version => 20140722024513) do | |||
| add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id" | |||
| create_table "rich_rich_files", :force => true do |t| | |||
| t.datetime "created_at", :null => false | |||
| t.datetime "updated_at", :null => false | |||
| t.string "rich_file_file_name" | |||
| t.string "rich_file_content_type" | |||
| t.integer "rich_file_file_size" | |||
| t.datetime "rich_file_updated_at" | |||
| t.string "owner_type" | |||
| t.integer "owner_id" | |||
| t.text "uri_cache" | |||
| t.string "simplified_type", :default => "file" | |||
| end | |||
| create_table "roles", :force => true do |t| | |||
| t.string "name", :limit => 30, :default => "", :null => false | |||
| t.integer "position", :default => 1 | |||
| @@ -172,6 +172,8 @@ Redmine::AccessControl.map do |map| | |||
| map.permission :view_issue_watchers, {}, :read => true | |||
| map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]} | |||
| map.permission :delete_issue_watchers, {:watchers => :destroy} | |||
| map.permission :add_gitlab_user, {:repositories => :committers}, :require => :loggedin | |||
| end | |||
| map.project_module :time_tracking do |map| | |||
| @@ -0,0 +1,7 @@ | |||
| # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | |||
| one: | |||
| project_id: | |||
| two: | |||
| project_id: | |||
| @@ -0,0 +1,7 @@ | |||
| # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | |||
| one: | |||
| user_id: | |||
| two: | |||
| user_id: | |||
| @@ -0,0 +1,7 @@ | |||
| require 'test_helper' | |||
| class GitlabProjectTest < ActiveSupport::TestCase | |||
| # test "the truth" do | |||
| # assert true | |||
| # end | |||
| end | |||
| @@ -0,0 +1,7 @@ | |||
| require 'test_helper' | |||
| class GitlabUserTest < ActiveSupport::TestCase | |||
| # test "the truth" do | |||
| # assert true | |||
| # end | |||
| end | |||