Commit 439d03bbedd2dfcd5ddcb5dc16afe610208188b0
1 parent
105f5ba3
Exists in
master
and in
4 other branches
Fix namespace api autocomplete
Showing
2 changed files
with
15 additions
and
6 deletions
Show diff stats
app/views/layouts/_init_auto_complete.html.haml
1 | :javascript | 1 | :javascript |
2 | $(function() { | 2 | $(function() { |
3 | - GitLab.GfmAutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.path}/members" if @project }"; | 3 | + GitLab.GfmAutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.id}/members" if @project }"; |
4 | GitLab.GfmAutoComplete.Members.params.private_token = "#{current_user.private_token}"; | 4 | GitLab.GfmAutoComplete.Members.params.private_token = "#{current_user.private_token}"; |
5 | 5 | ||
6 | GitLab.GfmAutoComplete.Emoji.data = #{raw emoji_autocomplete_source}; | 6 | GitLab.GfmAutoComplete.Emoji.data = #{raw emoji_autocomplete_source}; |
lib/api/helpers.rb
@@ -5,13 +5,18 @@ module Gitlab | @@ -5,13 +5,18 @@ module Gitlab | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def user_project | 7 | def user_project |
8 | - if @project ||= current_user.projects.find_by_id(params[:id]) || | ||
9 | - current_user.projects.find_by_path(params[:id]) | 8 | + @project ||= find_project |
9 | + @project || not_found! | ||
10 | + end | ||
11 | + | ||
12 | + def find_project | ||
13 | + project = Project.find_by_id(params[:id]) || Project.find_with_namespace(params[:id]) | ||
14 | + | ||
15 | + if project && can?(current_user, :read_project, project) | ||
16 | + project | ||
10 | else | 17 | else |
11 | - not_found! | 18 | + nil |
12 | end | 19 | end |
13 | - | ||
14 | - @project | ||
15 | end | 20 | end |
16 | 21 | ||
17 | def paginate(object) | 22 | def paginate(object) |
@@ -32,6 +37,10 @@ module Gitlab | @@ -32,6 +37,10 @@ module Gitlab | ||
32 | end | 37 | end |
33 | end | 38 | end |
34 | 39 | ||
40 | + def can?(object, action, subject) | ||
41 | + abilities.allowed?(object, action, subject) | ||
42 | + end | ||
43 | + | ||
35 | def attributes_for_keys(keys) | 44 | def attributes_for_keys(keys) |
36 | attrs = {} | 45 | attrs = {} |
37 | keys.each do |key| | 46 | keys.each do |key| |