Date: Thu, 17 Jul 2014 09:10:29 +0800
Subject: [PATCH 12/24] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E7=95=8C=E9=9D=A2=E7=9A=84=E5=85=B3=E6=B3=A8=E9=9C=80=E6=B1=82?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/layouts/base_users.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb
index 172bd67af..ac2b0e6fa 100644
--- a/app/views/layouts/base_users.html.erb
+++ b/app/views/layouts/base_users.html.erb
@@ -130,7 +130,7 @@
<%= link_to l(:label_x_user_fans, :count => User.current.watcher_users(User.current.id).count)+"("+@user.watcher_users.count.to_s+")", :controller=>"users", :action=>"user_fanslist" %>
- <%= link_to l(:label_requirement_focus)+"("+Bid.watched_by(@user).where('reward_type = ?', 1).count.to_s+")" ,:controller=>"users", :action=>"watch_bids"%>
+
<% if @user.id == User.current.id %>
From 12fb6bf5ca3c3ff67c144db3766379832f70db8a Mon Sep 17 00:00:00 2001
From: yanxd
Date: Thu, 17 Jul 2014 09:52:56 +0800
Subject: [PATCH 13/24] .
---
app/controllers/courses_controller.rb | 28 ++++++++---------
test/functional/courses_controller_test.rb | 36 ++++++++++++++++++----
2 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index a38d9f9c8..e10d6df88 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -217,7 +217,7 @@ class CoursesController < ApplicationController
@issue_category ||= IssueCategory.new
@member ||= @course.members.new
@trackers = Tracker.sorted.all
- end
+ end
def create
if User.current.user_extensions.identity
@@ -239,18 +239,18 @@ class CoursesController < ApplicationController
@trackers = Tracker.sorted.all
if User.current.user_extensions.identity == 0
- if @course.save
+ if @course.save
#unless User.current.admin?
- r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
- m = Member.new(:user => User.current, :roles => [r])
- m.project_id = -1
- course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
- #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
- if params[:course][:is_public] == '1'
- course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
- end
- @course.members << m
- @course.course_infos << course
+ r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
+ m = Member.new(:user => User.current, :roles => [r])
+ m.project_id = -1
+ course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
+ #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
+ if params[:course][:is_public] == '1'
+ course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
+ end
+ @course.members << m
+ @course.course_infos << course
#end
respond_to do |format|
format.html {
@@ -272,7 +272,7 @@ class CoursesController < ApplicationController
format.api { render_validation_errors(@course) }
end
end
- end
+ end
end
@@ -715,4 +715,4 @@ class CoursesController < ApplicationController
-end
\ No newline at end of file
+end
diff --git a/test/functional/courses_controller_test.rb b/test/functional/courses_controller_test.rb
index ebd0325b3..a1551a717 100644
--- a/test/functional/courses_controller_test.rb
+++ b/test/functional/courses_controller_test.rb
@@ -29,27 +29,51 @@ class CoursesControllerTest < ActionController::TestCase
assert_template :new
end
- def test_create_course_anyone_temporary
+ def test_create_course_with_access_control
@request.session[:user_id] = 5
Role.find_by_name("Non member").add_permission! :add_course #Non member
+ course_name = 'course_one'
post :create,
:class_period => '32',
:time => '2014',
:term => 'spring',
:course => {
- :name => 'course one',
+ :name => course_name, # names can't contain space.
:password => '1234',
:description => 'description',
- :is_public => '1234',
+ :is_public => '1',
:course_type => '1'
}
+
assert_response :found
- course = Course.find_by_name('course one')
- assert_redirected_to "courses/#{course.id}/settings"
- #assert_redirected_to "courses/#{course.id}/settings"
+ course = Course.find_by_name(course_name)
+ red_url = "courses/#{course.id}/settings"
+ assert_match %r(#{red_url}), @response.redirect_url
+ # 创建成功跳转settings方法会带参数一枚,故一下方法失败
+ # assert_redirected_to "courses/#{course.id}/settings"
end
+ def test_create_course_without_access_control
+ @request.session[:user_id] = 5
+ #Role.find_by_name("Non member").add_permission! :add_course #Non member
+ course_name = 'course_one'
+
+ post :create,
+ :class_period => '32',
+ :time => '2014',
+ :term => 'spring',
+ :course => {
+ :name => course_name, # names can't contain space.
+ :password => '1234',
+ :description => 'description',
+ :is_public => '1',
+ :course_type => '1'
+ }
+
+ assert_response :forbidden
+ end
+
# test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
# @request.session[:user_id] = 3
# get :index
From b60a0ddf592aa03d19f9bb738211fbdba0fb74da Mon Sep 17 00:00:00 2001
From: nwb
Date: Thu, 17 Jul 2014 09:55:40 +0800
Subject: [PATCH 14/24] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E7=BB=99gitlab?=
=?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E5=8F=8A?=
=?UTF-8?q?=E8=B5=8B=E6=9D=83=E9=99=90=E6=8E=A5=E5=8F=A3=202.=E6=B7=BB?=
=?UTF-8?q?=E5=8A=A0=E7=BB=99gitlab=E9=A1=B9=E7=9B=AE=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/users_controller.rb | 4 +-
app/helpers/gitlab_helper.rb | 60 ++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index d272a7678..a72444f0a 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -364,11 +364,13 @@ class UsersController < ApplicationController
def show
# 测试代码
- #login_gitlab("admin@local.host","19840410")
+ login_gitlab("admin@local.host","19840410")
#create_project("testproject1")
#create_project_for_user("testproject1","2")
#create_user("test","just test","123456","test@sina.com")
#delete_user("3")
+ add_user_to_project("1","2",GitlabHelper::GUEST)
+ delete_user_from_project("1","2")
# 测试结束
pre_count = 10 #limit
diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb
index 1b2906523..20faf551c 100644
--- a/app/helpers/gitlab_helper.rb
+++ b/app/helpers/gitlab_helper.rb
@@ -12,6 +12,12 @@ module GitlabHelper
REPO_IP_ADDRESS = "http://192.168.137.100"
GITLAB_API = "/api/v3"
+ # 用户在项目中的权限级别
+ GUEST = 10
+ REPORTER = 20
+ DEVELOPER = 30
+ MASTER = 40
+
def self.gitlab_token=(token)
Thread.current[:gitlab_token] = token
end
@@ -116,6 +122,8 @@ module GitlabHelper
end
# 删除用户
+ # user_id:用户在gitlab中的id
+ # add by nwb
def delete_user(user_id)
url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id
uri = URI.parse(url)
@@ -138,9 +146,56 @@ module GitlabHelper
end
# 给用户添加一个可操作的项目
- def add_project_to_user(project_name,user)
+ # 若用户已在该项目中,权限级别取新权限与现有权限的最大值
+ # project_id:项目在gitlab中的id user_id:用户在gitlab中的id
+ # access_level为用户在项目中的权限级别,对应如下:
+ #GUEST = 10
+ #REPORTER = 20
+ #DEVELOPER = 30
+ #MASTER = 40
+ # add by nwb
+ def add_user_to_project(project_id,user_id,access_level)
+ url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members"
+ uri = URI.parse(url)
+ data = {id:project_id,user_id:user_id,access_level:access_level, private_token:GitlabHelper.gitlab_token}
+ begin
+ res = Net::HTTP.post_form(uri, data)
+ if res.code == '201'
+ temp = ActiveSupport::JSON.decode(res.body)
+ return true
+ else
+ return false
+ end
+ rescue =>err
+ return false
+ end
end
+ # 从项目中删除用户
+ # project_id:项目在gitlab中的ids user_id:用户在gitlab中的id
+ # add by nwb
+ def delete_user_from_project(project_id,user_id)
+ url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members/" + user_id
+ uri = URI.parse(url)
+ data = {id:project_id,user_id:user_id,private_token:GitlabHelper.gitlab_token}
+ http = Net::HTTP.new uri.host, uri.port
+ begin
+ req = Net::HTTP::Delete.new(uri.request_uri)
+ req.form_data = data
+ res= http.start { |http| http.request req }
+ if res.code == '200'
+ temp = ActiveSupport::JSON.decode(res.body)
+ return true
+ else
+ return false
+ end
+ rescue =>err
+ return false
+ end
+ end
+
+ # 发送post消息
+ # add by nwb
def post(url, params)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
@@ -163,7 +218,8 @@ module GitlabHelper
end
end
-
+ # 发送get消息
+ # add by nwb
def get(url, params)
uri = URI.parse(url)
uri.query = URI.encode_www_form(params)
From 6a65b2a84b3f696d05cb0a8dff5f737d278ccdaa Mon Sep 17 00:00:00 2001
From: nwb
Date: Thu, 17 Jul 2014 10:52:01 +0800
Subject: [PATCH 15/24] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/users_controller.rb | 6 +++---
app/helpers/gitlab_helper.rb | 7 +++++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a72444f0a..24850a585 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -364,13 +364,13 @@ class UsersController < ApplicationController
def show
# 测试代码
- login_gitlab("admin@local.host","19840410")
+ #login_gitlab("admin@local.host","19840410")
#create_project("testproject1")
#create_project_for_user("testproject1","2")
#create_user("test","just test","123456","test@sina.com")
#delete_user("3")
- add_user_to_project("1","2",GitlabHelper::GUEST)
- delete_user_from_project("1","2")
+ #add_user_to_project("1","2",GitlabHelper::GUEST)
+ #delete_user_from_project("1","2")
# 测试结束
pre_count = 10 #limit
diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb
index 20faf551c..ceaaf6d21 100644
--- a/app/helpers/gitlab_helper.rb
+++ b/app/helpers/gitlab_helper.rb
@@ -1,6 +1,8 @@
# Gitlab5.3 API操作接口
# Add by nwb
# 暂时没支持SSH
+# 接口通过HTTP协议与服务器交互,理论上只要能安装gitlab的操作系统本接口都能支持
+# 本机的测试环境是Ubuntu 12.04
module GitlabHelper
@@ -8,6 +10,7 @@ module GitlabHelper
ROOT_PATH="/home/git/repositories/"
PROJECT_PATH_CUT = 40
# gitlab版本库所在服务器
+ # 注意REPO_IP_ADDRESS必须以http://开头,暂时只支持HTTP协议,未支持SSH
#REPO_IP_ADDRESS = "http://" + Setting.repository_domain
REPO_IP_ADDRESS = "http://192.168.137.100"
GITLAB_API = "/api/v3"
@@ -18,6 +21,8 @@ module GitlabHelper
DEVELOPER = 30
MASTER = 40
+ # gitlab的登录验证信息
+ # add by nwb
def self.gitlab_token=(token)
Thread.current[:gitlab_token] = token
end
@@ -211,7 +216,6 @@ module GitlabHelper
#request.set_form_data(params)
request.body = params.to_json
response = http.start { |http| http.request(request) }
- puts response.body.inspect
return JSON.parse response.body
rescue =>err
return nil
@@ -234,7 +238,6 @@ module GitlabHelper
request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0'
request['X-ACL-TOKEN'] = 'xxx_token'
response = http.start { |http| http.request request }
- puts response.body.inspect
return JSON.parse response.body
rescue =>err
return nil
From 615b3ac2acdb1bb14024fe593683d8ae6adc1bc2 Mon Sep 17 00:00:00 2001
From: nwb
Date: Thu, 17 Jul 2014 14:32:07 +0800
Subject: [PATCH 16/24] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=95=8C=E9=9D=A2?=
=?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/users_controller.rb | 10 ----------
app/views/layouts/base_courses.html.erb | 2 +-
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 24850a585..e81355260 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -363,16 +363,6 @@ class UsersController < ApplicationController
end
def show
- # 测试代码
- #login_gitlab("admin@local.host","19840410")
- #create_project("testproject1")
- #create_project_for_user("testproject1","2")
- #create_user("test","just test","123456","test@sina.com")
- #delete_user("3")
- #add_user_to_project("1","2",GitlabHelper::GUEST)
- #delete_user_from_project("1","2")
- # 测试结束
-
pre_count = 10 #limit
case params[:type]
when "1"
diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb
index 5958e18bd..38691bd1e 100644
--- a/app/views/layouts/base_courses.html.erb
+++ b/app/views/layouts/base_courses.html.erb
@@ -42,7 +42,7 @@
<%= link_to request.host()+"/course", :controller => 'courses', :action => 'index' %> |
<%= link_to "主页", home_path %>
- > <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'index' %>
+ > <%= link_to l(:label_course_all), :controller => 'courses', :action => 'index' %>
> <%= link_to @course.name, nil %> |
From 02b4029e8c6035525f911882a0e55d1c9e475b1d Mon Sep 17 00:00:00 2001
From: nwb
Date: Thu, 17 Jul 2014 15:05:49 +0800
Subject: [PATCH 17/24] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=95=8C=E9=9D=A2=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/files/_course_file.html.erb | 6 ++++--
app/views/files/_project_file.html.erb | 5 ++++-
config/locales/en.yml | 1 +
config/locales/zh.yml | 1 +
public/stylesheets/application.css | 2 +-
5 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb
index d9913539f..a1547bc2b 100644
--- a/app/views/files/_course_file.html.erb
+++ b/app/views/files/_course_file.html.erb
@@ -11,7 +11,9 @@
<%= link_to(l(:label_upload_files), 'javascript:void(0);', :class => 'icon m5p5 button_submit', :onclick => "$('#relation_file_div').slideUp();$('#upload_file_div').slideToggle('slow');") if User.current.allowed_to?(:manage_files, @course) %>
<%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @course) %>
-
+
+
+
<% if attachmenttypes.any? %>
@@ -24,7 +26,7 @@
<%= select_tag "attach_sufix_browse", content_tag(:option, l(:attachment_all), :value => '0') +options_for_select(sufixtypes),
:onchange => "course_attachment_contenttypes_searchex(this.value)" %>
<% end %>
-
+
<%= render :partial => 'course_new', locals: {course: @course} %>
diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb
index 1212db052..67067a638 100644
--- a/app/views/files/_project_file.html.erb
+++ b/app/views/files/_project_file.html.erb
@@ -11,7 +11,9 @@