diff options
| author | Timm Drevensek <abubadabu@gmail.com> | 2014-04-01 22:30:16 +0200 |
|---|---|---|
| committer | Timm Drevensek <abubadabu@gmail.com> | 2014-04-01 22:30:16 +0200 |
| commit | cb659e4c5a1c32bd2aa5c9994cd9d7b4a9841c9b (patch) | |
| tree | 4b28ca521d9d7420feb2ec705669b90e57a37d58 /lib | |
| parent | ea82bcd396c9e6ab8542474ee70365297a4ff2dc (diff) | |
| parent | 3b0510a7c124a8511966ad4785757bd4d78998ac (diff) | |
| download | gitlab-ce-cb659e4c5a1c32bd2aa5c9994cd9d7b4a9841c9b.tar.gz | |
Merge branch 'master' into request/relative_submodules
Conflicts:
CHANGELOG
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/api/api.rb | 1 | ||||
| -rw-r--r-- | lib/api/branches.rb | 85 | ||||
| -rw-r--r-- | lib/api/commits.rb | 11 | ||||
| -rw-r--r-- | lib/api/helpers.rb | 24 | ||||
| -rw-r--r-- | lib/api/repositories.rb | 62 | ||||
| -rw-r--r-- | lib/backup/database.rb | 5 | ||||
| -rw-r--r-- | lib/gitlab/ldap/user.rb | 13 | ||||
| -rwxr-xr-x | lib/support/init.d/gitlab | 22 | ||||
| -rw-r--r-- | lib/tasks/gitlab/check.rake | 15 | ||||
| -rw-r--r-- | lib/tasks/gitlab/db/drop_all_tables.rake | 10 |
10 files changed, 155 insertions, 93 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 7c4cdad7f0d..ce4cc8b34f7 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -45,5 +45,6 @@ module API mount Files mount Commits mount Namespaces + mount Branches end end diff --git a/lib/api/branches.rb b/lib/api/branches.rb new file mode 100644 index 00000000000..953c6100f8b --- /dev/null +++ b/lib/api/branches.rb @@ -0,0 +1,85 @@ +require 'mime/types' + +module API + # Projects API + class Branches < Grape::API + before { authenticate! } + before { authorize! :download_code, user_project } + + resource :projects do + # Get a project repository branches + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # GET /projects/:id/repository/branches + get ":id/repository/branches" do + present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project + end + + # Get a single branch + # + # Parameters: + # id (required) - The ID of a project + # branch (required) - The name of the branch + # Example Request: + # GET /projects/:id/repository/branches/:branch + get ":id/repository/branches/:branch" do + @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + not_found!("Branch does not exist") if @branch.nil? + present @branch, with: Entities::RepoObject, project: user_project + end + + # Protect a single branch + # + # Parameters: + # id (required) - The ID of a project + # branch (required) - The name of the branch + # Example Request: + # PUT /projects/:id/repository/branches/:branch/protect + put ":id/repository/branches/:branch/protect" do + authorize_admin_project + + @branch = user_project.repository.find_branch(params[:branch]) + not_found! unless @branch + protected_branch = user_project.protected_branches.find_by(name: @branch.name) + user_project.protected_branches.create(name: @branch.name) unless protected_branch + + present @branch, with: Entities::RepoObject, project: user_project + end + + # Unprotect a single branch + # + # Parameters: + # id (required) - The ID of a project + # branch (required) - The name of the branch + # Example Request: + # PUT /projects/:id/repository/branches/:branch/unprotect + put ":id/repository/branches/:branch/unprotect" do + authorize_admin_project + + @branch = user_project.repository.find_branch(params[:branch]) + not_found! unless @branch + protected_branch = user_project.protected_branches.find_by(name: @branch.name) + protected_branch.destroy if protected_branch + + present @branch, with: Entities::RepoObject, project: user_project + end + + # Create branch + # + # Parameters: + # id (required) - The ID of a project + # branch_name (required) - The name of the branch + # ref (required) - Create branch from commit sha or existing branch + # Example Request: + # POST /projects/:id/repository/branches + post ":id/repository/branches" do + authorize_push_project + @branch = CreateBranchService.new.execute(user_project, params[:branch_name], params[:ref], current_user) + + present @branch, with: Entities::RepoObject, project: user_project + end + end + end +end diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 33b8b3d2244..4a67313430a 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -1,21 +1,12 @@ require 'mime/types' module API - # Projects API + # Projects commits API class Commits < Grape::API before { authenticate! } before { authorize! :download_code, user_project } resource :projects do - helpers do - def handle_project_member_errors(errors) - if errors[:project_access].any? - error!(errors[:project_access], 422) - end - not_found! - end - end - # Get a project repository commits # # Parameters: diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index fc309f65a56..7ee4b9d1381 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -56,8 +56,12 @@ module API end end - def paginate(object) - object.page(params[:page]).per(params[:per_page].to_i) + def paginate(relation) + per_page = params[:per_page].to_i + paginated = relation.page(params[:page]).per(per_page) + add_pagination_headers(paginated, per_page) + + paginated end def authenticate! @@ -74,6 +78,10 @@ module API end end + def authorize_push_project + authorize! :push_code, user_project + end + def authorize_admin_project authorize! :admin_project, user_project end @@ -134,6 +142,18 @@ module API private + def add_pagination_headers(paginated, per_page) + request_url = request.url.split('?').first + + links = [] + links << %(<#{request_url}?page=#{paginated.current_page - 1}&per_page=#{per_page}>; rel="prev") unless paginated.first_page? + links << %(<#{request_url}?page=#{paginated.current_page + 1}&per_page=#{per_page}>; rel="next") unless paginated.last_page? + links << %(<#{request_url}?page=1&per_page=#{per_page}>; rel="first") + links << %(<#{request_url}?page=#{paginated.total_pages}&per_page=#{per_page}>; rel="last") + + header 'Link', links.join(', ') + end + def abilities @abilities ||= begin abilities = Six.new diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index ba53bf9baa4..076a9ceeb74 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -15,66 +15,6 @@ module API not_found! end end - - # Get a project repository branches - # - # Parameters: - # id (required) - The ID of a project - # Example Request: - # GET /projects/:id/repository/branches - get ":id/repository/branches" do - present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project - end - - # Get a single branch - # - # Parameters: - # id (required) - The ID of a project - # branch (required) - The name of the branch - # Example Request: - # GET /projects/:id/repository/branches/:branch - get ":id/repository/branches/:branch" do - @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } - not_found!("Branch does not exist") if @branch.nil? - present @branch, with: Entities::RepoObject, project: user_project - end - - # Protect a single branch - # - # Parameters: - # id (required) - The ID of a project - # branch (required) - The name of the branch - # Example Request: - # PUT /projects/:id/repository/branches/:branch/protect - put ":id/repository/branches/:branch/protect" do - authorize_admin_project - - @branch = user_project.repository.find_branch(params[:branch]) - not_found! unless @branch - protected_branch = user_project.protected_branches.find_by(name: @branch.name) - user_project.protected_branches.create(name: @branch.name) unless protected_branch - - present @branch, with: Entities::RepoObject, project: user_project - end - - # Unprotect a single branch - # - # Parameters: - # id (required) - The ID of a project - # branch (required) - The name of the branch - # Example Request: - # PUT /projects/:id/repository/branches/:branch/unprotect - put ":id/repository/branches/:branch/unprotect" do - authorize_admin_project - - @branch = user_project.repository.find_branch(params[:branch]) - not_found! unless @branch - protected_branch = user_project.protected_branches.find_by(name: @branch.name) - protected_branch.destroy if protected_branch - - present @branch, with: Entities::RepoObject, project: user_project - end - # Get a project repository tags # # Parameters: @@ -161,7 +101,7 @@ module API repo = user_project.repository ref = params[:sha] format = params[:format] - storage_path = Rails.root.join("tmp", "repositories") + storage_path = Gitlab.config.gitlab.repository_downloads_path file_path = repo.archive_repo(ref, storage_path, format) if file_path && File.exists?(file_path) diff --git a/lib/backup/database.rb b/lib/backup/database.rb index 6552f45ff0b..7b6908ccad8 100644 --- a/lib/backup/database.rb +++ b/lib/backup/database.rb @@ -29,9 +29,10 @@ module Backup print "Restoring MySQL database #{config['database']} ... " system('mysql', *mysql_args, config['database'], in: db_file_name) when "postgresql" then - puts "Destructively rebuilding database schema for RAILS_ENV #{Rails.env}" - Rake::Task["db:schema:load"].invoke print "Restoring PostgreSQL database #{config['database']} ... " + # Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE + # statements like MySQL. + Rake::Task["gitlab:db:drop_all_tables"].invoke pg_env system('psql', config['database'], '-f', db_file_name) end diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 456a61b9e43..01d86430f02 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -81,16 +81,17 @@ module Gitlab private - def find_by_uid(uid) - model.where(provider: provider, extern_uid: uid).last + def find_by_uid_and_provider + find_by_uid(uid) end - def username - (auth.info.nickname || samaccountname).to_s.force_encoding("utf-8") + def find_by_uid(uid) + # LDAP distinguished name is case-insensitive + model.where("provider = ? and lower(extern_uid) = ?", provider, uid.downcase).last end - def samaccountname - (auth.extra[:raw_info][:samaccountname] || []).first + def username + auth.info.nickname.to_s.force_encoding("utf-8") end def provider diff --git a/lib/support/init.d/gitlab b/lib/support/init.d/gitlab index 427e6d697e5..3dd4465a6d8 100755 --- a/lib/support/init.d/gitlab +++ b/lib/support/init.d/gitlab @@ -149,7 +149,7 @@ exit_if_not_running(){ } ## Starts Unicorn and Sidekiq if they're not running. -start() { +start_gitlab() { check_stale_pids if [ "$web_status" != "0" -a "$sidekiq_status" != "0" ]; then @@ -167,7 +167,7 @@ start() { # Remove old socket if it exists rm -f "$socket_path"/gitlab.socket 2>/dev/null # Start the web server - RAILS_ENV=$RAILS_ENV script/web start & + RAILS_ENV=$RAILS_ENV script/web start fi # If sidekiq is already running, don't start it again. @@ -184,7 +184,7 @@ start() { } ## Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them. -stop() { +stop_gitlab() { exit_if_not_running if [ "$web_status" = "0" -a "$sidekiq_status" = "0" ]; then @@ -246,7 +246,7 @@ print_status() { } ## Tells unicorn to reload it's config and Sidekiq to restart -reload(){ +reload_gitlab(){ exit_if_not_running if [ "$wpid" = "0" ];then echo "The GitLab Unicorn Web server is not running thus its configuration can't be reloaded." @@ -263,12 +263,12 @@ reload(){ } ## Restarts Sidekiq and Unicorn. -restart(){ +restart_gitlab(){ check_status if [ "$web_status" = "0" -o "$sidekiq_status" = "0" ]; then - stop + stop_gitlab fi - start + start_gitlab } @@ -276,16 +276,16 @@ restart(){ case "$1" in start) - start + start_gitlab ;; stop) - stop + stop_gitlab ;; restart) - restart + restart_gitlab ;; reload|force-reload) - reload + reload_gitlab ;; status) print_status diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 071760c0c36..3b9b2531bf7 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -677,7 +677,20 @@ namespace :gitlab do end def filter - Net::LDAP::Filter.present?(ldap_config.uid) + uid_filter = Net::LDAP::Filter.present?(ldap_config.uid) + if user_filter + Net::LDAP::Filter.join(uid_filter, user_filter) + else + uid_filter + end + end + + def user_filter + if ldap_config['user_filter'] && ldap_config.user_filter.present? + Net::LDAP::Filter.construct(ldap_config.user_filter) + else + nil + end end def ldap diff --git a/lib/tasks/gitlab/db/drop_all_tables.rake b/lib/tasks/gitlab/db/drop_all_tables.rake new file mode 100644 index 00000000000..a66030ab93a --- /dev/null +++ b/lib/tasks/gitlab/db/drop_all_tables.rake @@ -0,0 +1,10 @@ +namespace :gitlab do + namespace :db do + task drop_all_tables: :environment do + connection = ActiveRecord::Base.connection + connection.tables.each do |table| + connection.drop_table(table) + end + end + end +end |
