Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-03 12:04:04 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-03 12:04:04 +0300
commitb118f648cb393d9ef4e1e510e86b72cb3e8c98f3 (patch)
treee42d624f19045722edb295c889c50e7018fc43fb /lib
parentd2fffff0ecfbc5eadf754905cee8a8593ed3c623 (diff)
parentb8433cb886abfdc7eae86c1789c0f1c5ff56204d (diff)
Merge branch 'master' of github.com:gitlabhq/gitlabhq
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb14
-rw-r--r--lib/api/users.rb123
-rw-r--r--lib/backup/database.rb7
-rw-r--r--lib/backup/manager.rb2
-rw-r--r--lib/backup/repository.rb5
-rw-r--r--lib/backup/uploads.rb6
-rw-r--r--lib/gitlab/markdown/relative_link_filter.rb14
-rw-r--r--lib/rouge/formatters/html_gitlab.rb12
-rw-r--r--lib/tasks/gitlab/check.rake8
-rw-r--r--lib/tasks/gitlab/import.rake4
10 files changed, 173 insertions, 22 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index ecf1412dee5..b5556682449 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -6,6 +6,10 @@ module API
class UserBasic < UserSafe
expose :id, :state, :avatar_url
+
+ expose :web_url do |user, options|
+ Rails.application.routes.url_helpers.user_url(user)
+ end
end
class User < UserBasic
@@ -31,6 +35,10 @@ module API
expose :private_token
end
+ class Email < Grape::Entity
+ expose :id, :email
+ end
+
class Hook < Grape::Entity
expose :id, :url, :created_at
end
@@ -59,6 +67,7 @@ module API
expose :namespace
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
expose :avatar_url
+ expose :star_count, :forks_count
end
class ProjectMember < UserBasic
@@ -69,6 +78,11 @@ module API
class Group < Grape::Entity
expose :id, :name, :path, :description
+ expose :avatar_url
+
+ expose :web_url do |group, options|
+ Rails.application.routes.url_helpers.group_url(group)
+ end
end
class GroupDetail < Group
diff --git a/lib/api/users.rb b/lib/api/users.rb
index c468371d3d4..ee29f952246 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -131,11 +131,11 @@ module API
# Add ssh key to a specified user. Only available to admin users.
#
# Parameters:
- # id (required) - The ID of a user
- # key (required) - New SSH Key
- # title (required) - New SSH Key's title
+ # id (required) - The ID of a user
+ # key (required) - New SSH Key
+ # title (required) - New SSH Key's title
# Example Request:
- # POST /users/:id/keys
+ # POST /users/:id/keys
post ":id/keys" do
authenticated_as_admin!
required_attributes! [:title, :key]
@@ -153,9 +153,9 @@ module API
# Get ssh keys of a specified user. Only available to admin users.
#
# Parameters:
- # uid (required) - The ID of a user
+ # uid (required) - The ID of a user
# Example Request:
- # GET /users/:uid/keys
+ # GET /users/:uid/keys
get ':uid/keys' do
authenticated_as_admin!
user = User.find_by(id: params[:uid])
@@ -185,6 +185,65 @@ module API
end
end
+ # Add email to a specified user. Only available to admin users.
+ #
+ # Parameters:
+ # id (required) - The ID of a user
+ # email (required) - Email address
+ # Example Request:
+ # POST /users/:id/emails
+ post ":id/emails" do
+ authenticated_as_admin!
+ required_attributes! [:email]
+
+ user = User.find(params[:id])
+ attrs = attributes_for_keys [:email]
+ email = user.emails.new attrs
+ if email.save
+ NotificationService.new.new_email(email)
+ present email, with: Entities::Email
+ else
+ render_validation_error!(email)
+ end
+ end
+
+ # Get emails of a specified user. Only available to admin users.
+ #
+ # Parameters:
+ # uid (required) - The ID of a user
+ # Example Request:
+ # GET /users/:uid/emails
+ get ':uid/emails' do
+ authenticated_as_admin!
+ user = User.find_by(id: params[:uid])
+ not_found!('User') unless user
+
+ present user.emails, with: Entities::Email
+ end
+
+ # Delete existing email of a specified user. Only available to admin
+ # users.
+ #
+ # Parameters:
+ # uid (required) - The ID of a user
+ # id (required) - Email ID
+ # Example Request:
+ # DELETE /users/:uid/emails/:id
+ delete ':uid/emails/:id' do
+ authenticated_as_admin!
+ user = User.find_by(id: params[:uid])
+ not_found!('User') unless user
+
+ begin
+ email = user.emails.find params[:id]
+ email.destroy
+
+ user.update_secondary_emails!
+ rescue ActiveRecord::RecordNotFound
+ not_found!('Email')
+ end
+ end
+
# Delete user. Available only for admin
#
# Example Request:
@@ -289,6 +348,58 @@ module API
rescue
end
end
+
+ # Get currently authenticated user's emails
+ #
+ # Example Request:
+ # GET /user/emails
+ get "emails" do
+ present current_user.emails, with: Entities::Email
+ end
+
+ # Get single email owned by currently authenticated user
+ #
+ # Example Request:
+ # GET /user/emails/:id
+ get "emails/:id" do
+ email = current_user.emails.find params[:id]
+ present email, with: Entities::Email
+ end
+
+ # Add new email to currently authenticated user
+ #
+ # Parameters:
+ # email (required) - Email address
+ # Example Request:
+ # POST /user/emails
+ post "emails" do
+ required_attributes! [:email]
+
+ attrs = attributes_for_keys [:email]
+ email = current_user.emails.new attrs
+ if email.save
+ NotificationService.new.new_email(email)
+ present email, with: Entities::Email
+ else
+ render_validation_error!(email)
+ end
+ end
+
+ # Delete existing email of currently authenticated user
+ #
+ # Parameters:
+ # id (required) - EMail ID
+ # Example Request:
+ # DELETE /user/emails/:id
+ delete "emails/:id" do
+ begin
+ email = current_user.emails.find params[:id]
+ email.destroy
+
+ current_user.update_secondary_emails!
+ rescue
+ end
+ end
end
end
end
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index c5a5396cbbf..bbb230a10f0 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -7,7 +7,11 @@ module Backup
def initialize
@config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
@db_dir = File.join(Gitlab.config.backup.path, 'db')
- FileUtils.mkdir_p(@db_dir) unless Dir.exists?(@db_dir)
+ FileUtils.rm_rf(@db_dir)
+ # Ensure the parent dir of @db_dir exists
+ FileUtils.mkdir_p(Gitlab.config.backup.path)
+ # Fail if somebody raced to create @db_dir before us
+ FileUtils.mkdir(@db_dir, mode: 0700)
end
def dump
@@ -25,7 +29,6 @@ module Backup
abort 'Backup failed' unless success
$progress.print 'Compressing database ... '
- FileUtils.rm_f db_file_name_gz
success = system('gzip', db_file_name)
report_success(success)
abort 'Backup failed: compress error' unless success
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index 5103b265ed4..13c68d9354f 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -16,8 +16,6 @@ module Backup
file << s.to_yaml.gsub(/^---\n/,'')
end
- FileUtils.chmod(0700, folders_to_backup)
-
# create archive
$progress.print "Creating backup archive: #{tar_file} ... "
# Set file permissions on open to prevent chmod races.
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index dfb2da9f84e..4d70f7883dd 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -130,7 +130,10 @@ module Backup
def prepare
FileUtils.rm_rf(backup_repos_path)
- FileUtils.mkdir_p(backup_repos_path)
+ # Ensure the parent dir of backup_repos_path exists
+ FileUtils.mkdir_p(Gitlab.config.backup.path)
+ # Fail if somebody raced to create backup_repos_path before us
+ FileUtils.mkdir(backup_repos_path, mode: 0700)
end
def silent
diff --git a/lib/backup/uploads.rb b/lib/backup/uploads.rb
index bf43610acf6..1f9626644e6 100644
--- a/lib/backup/uploads.rb
+++ b/lib/backup/uploads.rb
@@ -10,7 +10,11 @@ module Backup
# Copy uploads from public/uploads to backup/uploads
def dump
- FileUtils.mkdir_p(backup_uploads_dir)
+ FileUtils.rm_rf(backup_uploads_dir)
+ # Ensure the parent dir of backup_uploads_dir exists
+ FileUtils.mkdir_p(Gitlab.config.backup.path)
+ # Fail if somebody raced to create backup_uploads_dir before us
+ FileUtils.mkdir(backup_uploads_dir, mode: 0700)
FileUtils.cp_r(app_uploads_dir, backup_dir)
end
diff --git a/lib/gitlab/markdown/relative_link_filter.rb b/lib/gitlab/markdown/relative_link_filter.rb
index 9de2b24a9da..30f50b82996 100644
--- a/lib/gitlab/markdown/relative_link_filter.rb
+++ b/lib/gitlab/markdown/relative_link_filter.rb
@@ -98,15 +98,25 @@ module Gitlab
#
# Returns a String
def path_type(path)
- if repository.tree(current_sha, path).entries.any?
+ unescaped_path = Addressable::URI.unescape(path)
+
+ if tree?(unescaped_path)
'tree'
- elsif repository.blob_at(current_sha, path).try(:image?)
+ elsif image?(unescaped_path)
'raw'
else
'blob'
end
end
+ def tree?(path)
+ repository.tree(current_sha, path).entries.any?
+ end
+
+ def image?(path)
+ repository.blob_at(current_sha, path).try(:image?)
+ end
+
def current_sha
context[:commit].try(:id) ||
ref ? repository.commit(ref).try(:sha) : repository.head_commit.sha
diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb
index 485af6832d7..092a920a0c4 100644
--- a/lib/rouge/formatters/html_gitlab.rb
+++ b/lib/rouge/formatters/html_gitlab.rb
@@ -148,6 +148,12 @@ module Rouge
end
end
+ def wrap_values(val, element)
+ lines = val.split("\n")
+ lines = lines.map{ |x| "<span #{element}>#{x}</span>" }
+ lines.join("\n")
+ end
+
def span(tok, val)
# http://stackoverflow.com/a/1600584/2587286
val = CGI.escapeHTML(val)
@@ -155,11 +161,13 @@ module Rouge
if tok.shortname.empty?
val
else
+ # In the case of multi-line values (e.g. comments), we need to apply
+ # styling to each line since span elements are inline.
if @inline_theme
rules = @inline_theme.style_for(tok).rendered_rules
- "<span style=\"#{rules.to_a.join(';')}\">#{val}</span>"
+ wrap_values(val, "style=\"#{rules.to_a.join(';')}\"")
else
- "<span class=\"#{tok.shortname}\">#{val}</span>"
+ wrap_values(val, "class=\"#{tok.shortname}\"")
end
end
end
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index aed84226a2f..badb47c6779 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -485,7 +485,8 @@ namespace :gitlab do
if project.empty_repo?
puts "repository is empty".magenta
- elsif File.realpath(project_hook_directory) == File.realpath(gitlab_shell_hooks_path)
+ elsif File.directory?(project_hook_directory) && File.directory?(gitlab_shell_hooks_path) &&
+ (File.realpath(project_hook_directory) == File.realpath(gitlab_shell_hooks_path))
puts 'ok'.green
else
puts "wrong or missing hooks".red
@@ -754,7 +755,7 @@ namespace :gitlab do
print "Ruby version >= #{required_version} ? ... "
if current_version.valid? && required_version <= current_version
- puts "yes (#{current_version})".green
+ puts "yes (#{current_version})".green
else
puts "no".red
try_fixing_it(
@@ -772,7 +773,7 @@ namespace :gitlab do
print "Git version >= #{required_version} ? ... "
if current_version.valid? && required_version <= current_version
- puts "yes (#{current_version})".green
+ puts "yes (#{current_version})".green
else
puts "no".red
try_fixing_it(
@@ -806,4 +807,3 @@ namespace :gitlab do
end
end
end
-
diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake
index 5f83e5e8e7f..c1ee271ae2b 100644
--- a/lib/tasks/gitlab/import.rake
+++ b/lib/tasks/gitlab/import.rake
@@ -62,11 +62,11 @@ namespace :gitlab do
project = Projects::CreateService.new(user, project_params).execute
- if project.valid?
+ if project.persisted?
puts " * Created #{project.name} (#{repo_path})".green
else
puts " * Failed trying to create #{project.name} (#{repo_path})".red
- puts " Validation Errors: #{project.errors.messages}".red
+ puts " Errors: #{project.errors.messages}".red
end
end
end