summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorkaren Carias <karen@gitlab.com>2015-09-30 13:33:51 -0700
committerkaren Carias <karen@gitlab.com>2015-09-30 13:33:51 -0700
commit126dd008e110dce5dfe7d1d076bc57f33250ee7b (patch)
tree4ce96f2fd7e50faff65df7b556153c08d16a888c /lib/api
parent6a1d695f861e4c5251a2333c673f78705b34891f (diff)
parent54452412f765d9e6e6166e105db9adbc7553aec2 (diff)
downloadgitlab-ce-126dd008e110dce5dfe7d1d076bc57f33250ee7b.tar.gz
solved conflict
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb6
-rw-r--r--lib/api/helpers.rb43
-rw-r--r--lib/api/merge_requests.rb2
-rw-r--r--lib/api/project_hooks.rb6
-rw-r--r--lib/api/projects.rb36
-rw-r--r--lib/api/services.rb14
-rw-r--r--lib/api/users.rb13
7 files changed, 72 insertions, 48 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8dddcd7ccc3..9620d36ac41 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -8,7 +8,7 @@ module API
expose :id, :state, :avatar_url
expose :web_url do |user, options|
- Rails.application.routes.url_helpers.user_url(user)
+ Gitlab::Application.routes.url_helpers.user_url(user)
end
end
@@ -45,7 +45,7 @@ module API
class ProjectHook < Hook
expose :project_id, :push_events
- expose :issues_events, :merge_requests_events, :tag_push_events
+ expose :issues_events, :merge_requests_events, :tag_push_events, :note_events, :enable_ssl_verification
end
class ForkedFromProject < Grape::Entity
@@ -81,7 +81,7 @@ module API
expose :avatar_url
expose :web_url do |group, options|
- Rails.application.routes.url_helpers.group_url(group)
+ Gitlab::Application.routes.url_helpers.group_url(group)
end
end
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 76c9cc2e3a4..7fada98fcdc 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -148,15 +148,14 @@ module API
end
end
- def attributes_for_keys(keys)
+ def attributes_for_keys(keys, custom_params = nil)
+ params_hash = custom_params || params
attrs = {}
-
keys.each do |key|
if params[key].present? or (params.has_key?(key) and params[key] == false)
attrs[key] = params[key]
end
end
-
ActionController::Parameters.new(attrs).permit!
end
@@ -246,6 +245,44 @@ module API
error!({ 'message' => message }, status)
end
+ # Projects helpers
+
+ def filter_projects(projects)
+ # If the archived parameter is passed, limit results accordingly
+ if params[:archived].present?
+ projects = projects.where(archived: parse_boolean(params[:archived]))
+ end
+
+ if params[:search].present?
+ projects = projects.search(params[:search])
+ end
+
+ if params[:ci_enabled_first].present?
+ projects.includes(:gitlab_ci_service).
+ reorder("services.active DESC, projects.#{project_order_by} #{project_sort}")
+ else
+ projects.reorder(project_order_by => project_sort)
+ end
+ end
+
+ def project_order_by
+ order_fields = %w(id name path created_at updated_at last_activity_at)
+
+ if order_fields.include?(params['order_by'])
+ params['order_by']
+ else
+ 'created_at'
+ end
+ end
+
+ def project_sort
+ if params["sort"] == 'asc'
+ :asc
+ else
+ :desc
+ end
+ end
+
private
def add_pagination_headers(paginated, per_page)
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 7412274b045..63ea2f05438 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -55,7 +55,7 @@ module API
else merge_requests
end
- merge_requests.reorder(issuable_order_by => issuable_sort)
+ merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort)
present paginate(merge_requests), with: Entities::MergeRequest
end
diff --git a/lib/api/project_hooks.rb b/lib/api/project_hooks.rb
index ad4d2e65dfd..882d1a083ad 100644
--- a/lib/api/project_hooks.rb
+++ b/lib/api/project_hooks.rb
@@ -44,7 +44,8 @@ module API
:issues_events,
:merge_requests_events,
:tag_push_events,
- :note_events
+ :note_events,
+ :enable_ssl_verification
]
@hook = user_project.hooks.new(attrs)
@@ -75,7 +76,8 @@ module API
:issues_events,
:merge_requests_events,
:tag_push_events,
- :note_events
+ :note_events,
+ :enable_ssl_verification
]
if @hook.update_attributes attrs
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 1f2251c9b9c..c2fb36b4143 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -11,42 +11,6 @@ module API
attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true
attrs
end
-
- def filter_projects(projects)
- # If the archived parameter is passed, limit results accordingly
- if params[:archived].present?
- projects = projects.where(archived: parse_boolean(params[:archived]))
- end
-
- if params[:search].present?
- projects = projects.search(params[:search])
- end
-
- if params[:ci_enabled_first].present?
- projects.includes(:gitlab_ci_service).
- reorder("services.active DESC, projects.#{project_order_by} #{project_sort}")
- else
- projects.reorder(project_order_by => project_sort)
- end
- end
-
- def project_order_by
- order_fields = %w(id name path created_at updated_at last_activity_at)
-
- if order_fields.include?(params['order_by'])
- params['order_by']
- else
- 'created_at'
- end
- end
-
- def project_sort
- if params["sort"] == 'asc'
- :asc
- else
- :desc
- end
- end
end
# Get a projects list for authenticated user
diff --git a/lib/api/services.rb b/lib/api/services.rb
index 73645cedea4..6727e80ac1e 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -20,7 +20,7 @@ module API
end
required_attributes! validators.map(&:attributes).flatten.uniq
- attrs = attributes_for_keys service_attributes
+ attrs = attributes_for_keys service_attributes
if project_service.update_attributes(attrs.merge(active: true))
true
@@ -41,7 +41,7 @@ module API
attrs = service_attributes.inject({}) do |hash, key|
hash.merge!(key => nil)
end
-
+
if project_service.update_attributes(attrs.merge(active: false))
true
else
@@ -49,6 +49,16 @@ module API
end
end
end
+
+ # Get <service_slug> service settings for project
+ #
+ # Example Request:
+ #
+ # GET /project/:id/services/gitlab-ci
+ #
+ get ':id/services/:service_slug' do
+ present project_service
+ end
end
end
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index ee29f952246..a98d668e02d 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -3,7 +3,7 @@ module API
class Users < Grape::API
before { authenticate! }
- resource :users do
+ resource :users, requirements: { uid: /[0-9]*/, id: /[0-9]*/ } do
# Get a users list
#
# Example Request:
@@ -121,6 +121,17 @@ module API
User.where(username: attrs[:username]).
where.not(id: user.id).count > 0
+ identity_attrs = attributes_for_keys [:provider, :extern_uid]
+ if identity_attrs.any?
+ identity = user.identities.find_by(provider: identity_attrs[:provider])
+ if identity
+ identity.update_attributes(identity_attrs)
+ else
+ identity = user.identities.build(identity_attrs)
+ identity.save
+ end
+ end
+
if user.update_attributes(attrs)
present user, with: Entities::UserFull
else