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:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-04-13 18:38:59 +0300
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-04-13 18:38:59 +0300
commitf07316f27cc1a5d354bc82b4caa1de703a3bcb5e (patch)
tree68c8f99f8df9375c9644993cf0bbd2f92cf9bfdd /lib
parent6f6d2d0ad5039fa8ace7e09c4f5867bb680b0f79 (diff)
parent3463ffde9e3ef425fbaa6093f01212cccb01707b (diff)
Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into auto-fsck
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb15
-rw-r--r--lib/api/groups.rb28
-rw-r--r--lib/api/helpers.rb7
-rw-r--r--lib/api/issues.rb23
-rw-r--r--lib/api/projects.rb34
-rw-r--r--lib/api/repositories.rb1
-rw-r--r--lib/gitlab.rb3
-rw-r--r--lib/gitlab/metrics.rb10
-rw-r--r--lib/gitlab/o_auth/user.rb10
-rw-r--r--lib/gitlab/saml/user.rb3
-rw-r--r--lib/tasks/gemojione.rake15
11 files changed, 136 insertions, 13 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 939469b3886..60b9f5e0ece 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -263,14 +263,19 @@ module API
expose :id, :path, :kind
end
- class ProjectAccess < Grape::Entity
+ class Member < Grape::Entity
expose :access_level
- expose :notification_level
+ expose :notification_level do |member, options|
+ if member.notification_setting
+ NotificationSetting.levels[member.notification_setting.level]
+ end
+ end
end
- class GroupAccess < Grape::Entity
- expose :access_level
- expose :notification_level
+ class ProjectAccess < Member
+ end
+
+ class GroupAccess < Member
end
class ProjectService < Grape::Entity
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index c165de21a75..91e420832f3 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -23,8 +23,10 @@ module API
# Create group. Available only for users who can create groups.
#
# Parameters:
- # name (required) - The name of the group
- # path (required) - The path of the group
+ # name (required) - The name of the group
+ # path (required) - The path of the group
+ # description (optional) - The description of the group
+ # visibility_level (optional) - The visibility level of the group
# Example Request:
# POST /groups
post do
@@ -42,6 +44,28 @@ module API
end
end
+ # Update group. Available only for users who can administrate groups.
+ #
+ # Parameters:
+ # id (required) - The ID of a group
+ # path (optional) - The path of the group
+ # description (optional) - The description of the group
+ # visibility_level (optional) - The visibility level of the group
+ # Example Request:
+ # PUT /groups/:id
+ put ':id' do
+ group = find_group(params[:id])
+ authorize! :admin_group, group
+
+ attrs = attributes_for_keys [:name, :path, :description, :visibility_level]
+
+ if ::Groups::UpdateService.new(group, current_user, attrs).execute
+ present group, with: Entities::GroupDetail
+ else
+ render_validation_error!(group)
+ end
+ end
+
# Get a single group, with containing projects
#
# Parameters:
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 4921ae99e78..5bbf721321d 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -91,8 +91,7 @@ module API
if can?(current_user, :read_group, group)
group
else
- forbidden!("#{current_user.username} lacks sufficient "\
- "access to #{group.name}")
+ not_found!('Group')
end
end
@@ -241,6 +240,10 @@ module API
render_api_error!('413 Request Entity Too Large', 413)
end
+ def not_modified!
+ render_api_error!('304 Not Modified', 304)
+ end
+
def render_validation_error!(model)
if model.errors.any?
render_api_error!(model.errors.messages || '400 Bad Request', 400)
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index c4ea05ee6cf..850e99981ff 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -195,6 +195,29 @@ module API
end
end
+ # Move an existing issue
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # issue_id (required) - The ID of a project issue
+ # to_project_id (required) - The ID of the new project
+ # Example Request:
+ # POST /projects/:id/issues/:issue_id/move
+ post ':id/issues/:issue_id/move' do
+ required_attributes! [:to_project_id]
+
+ issue = user_project.issues.find(params[:issue_id])
+ new_project = Project.find(params[:to_project_id])
+
+ begin
+ issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
+ present issue, with: Entities::Issue, current_user: current_user
+ rescue ::Issues::MoveService::MoveError => error
+ render_api_error!(error.message, 400)
+ end
+ end
+
+ #
# Delete a project issue
#
# Parameters:
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 24b31005475..cc2c7a0c503 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -272,6 +272,40 @@ module API
present user_project, with: Entities::Project
end
+ # Star project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # POST /projects/:id/star
+ post ':id/star' do
+ if current_user.starred?(user_project)
+ not_modified!
+ else
+ current_user.toggle_star(user_project)
+ user_project.reload
+
+ present user_project, with: Entities::Project
+ end
+ end
+
+ # Unstar project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # DELETE /projects/:id/star
+ delete ':id/star' do
+ if current_user.starred?(user_project)
+ current_user.toggle_star(user_project)
+ user_project.reload
+
+ present user_project, with: Entities::Project
+ else
+ not_modified!
+ end
+ end
+
# Remove project
#
# Parameters:
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 0d0f0d4616d..62161aadb9a 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -98,7 +98,6 @@ module API
authorize! :download_code, user_project
begin
- RepositoryArchiveCacheWorker.perform_async
header *Gitlab::Workhorse.send_git_archive(user_project, params[:sha], params[:format])
rescue
not_found!('File')
diff --git a/lib/gitlab.rb b/lib/gitlab.rb
index 6108697bc20..7479e729db1 100644
--- a/lib/gitlab.rb
+++ b/lib/gitlab.rb
@@ -1,4 +1,7 @@
require 'gitlab/git'
module Gitlab
+ def self.com?
+ Gitlab.config.gitlab.url == 'https://gitlab.com'
+ end
end
diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb
index 2a0a5629be5..484970c5a10 100644
--- a/lib/gitlab/metrics.rb
+++ b/lib/gitlab/metrics.rb
@@ -104,6 +104,16 @@ module Gitlab
retval
end
+ # Adds a tag to the current transaction (if any)
+ #
+ # name - The name of the tag to add.
+ # value - The value of the tag.
+ def self.tag_transaction(name, value)
+ trans = current_transaction
+
+ trans.add_tag(name, value) if trans
+ end
+
# When enabled this should be set before being used as the usual pattern
# "@foo ||= bar" is _not_ thread-safe.
if enabled?
diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb
index 832fb08a526..356e96fcbab 100644
--- a/lib/gitlab/o_auth/user.rb
+++ b/lib/gitlab/o_auth/user.rb
@@ -54,6 +54,12 @@ module Gitlab
@user ||= build_new_user
end
+ if external_provider? && @user
+ @user.external = true
+ elsif @user
+ @user.external = false
+ end
+
@user
end
@@ -113,6 +119,10 @@ module Gitlab
end
end
+ def external_provider?
+ Gitlab.config.omniauth.external_providers.include?(auth_hash.provider)
+ end
+
def block_after_signup?
if creating_linked_ldap_user?
ldap_config.block_auto_created_users
diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb
index c1072452abe..dba4bbfc899 100644
--- a/lib/gitlab/saml/user.rb
+++ b/lib/gitlab/saml/user.rb
@@ -26,7 +26,7 @@ module Gitlab
@user ||= build_new_user
end
- if external_users_enabled?
+ if external_users_enabled? && @user
# Check if there is overlap between the user's groups and the external groups
# setting then set user as external or internal.
if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
@@ -48,6 +48,7 @@ module Gitlab
end
def changed?
+ return true unless gl_user
gl_user.changed? || gl_user.identities.any?(&:changed?)
end
diff --git a/lib/tasks/gemojione.rake b/lib/tasks/gemojione.rake
index 7ec00a898fd..030ee8bafcb 100644
--- a/lib/tasks/gemojione.rake
+++ b/lib/tasks/gemojione.rake
@@ -5,12 +5,23 @@ namespace :gemojione do
require 'json'
dir = Gemojione.index.images_path
+ digests = []
+ aliases = Hash.new { |hash, key| hash[key] = [] }
+ aliases_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json')
- digests = AwardEmoji.emojis.map do |name, emoji_hash|
+ JSON.parse(File.read(aliases_path)).each do |alias_name, real_name|
+ aliases[real_name] << alias_name
+ end
+
+ AwardEmoji.emojis.map do |name, emoji_hash|
fpath = File.join(dir, "#{emoji_hash['unicode']}.png")
digest = Digest::SHA256.file(fpath).hexdigest
- { name: name, unicode: emoji_hash['unicode'], digest: digest }
+ digests << { name: name, unicode: emoji_hash['unicode'], digest: digest }
+
+ aliases[name].each do |alias_name|
+ digests << { name: alias_name, unicode: emoji_hash['unicode'], digest: digest }
+ end
end
out = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')