Commit d0165c82 authored by Clement Ho's avatar Clement Ho

Add author_username and assignee_username

parent fc6eab69
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
const validTokenKeys = [{ const validTokenKeys = [{
key: 'author', key: 'author',
type: 'string', type: 'string',
param: 'id', param: 'username',
},{ },{
key: 'assignee', key: 'assignee',
type: 'string', type: 'string',
param: 'id', param: 'username',
},{ },{
key: 'milestone', key: 'milestone',
type: 'string', type: 'string',
......
...@@ -165,31 +165,43 @@ class IssuableFinder ...@@ -165,31 +165,43 @@ class IssuableFinder
end end
end end
def assignee? def assignee_id?
params[:assignee_id].present? params[:assignee_id].present?
end end
def assignee_username?
params[:assignee_username].present?
end
def assignee def assignee
return @assignee if defined?(@assignee) return @assignee if defined?(@assignee)
@assignee = @assignee =
if assignee? && params[:assignee_id] != NONE if assignee_id? && params[:assignee_id] != NONE
User.find(params[:assignee_id]) User.find(params[:assignee_id])
elsif assignee_username? && params[:assignee_username] != NONE
User.find_by(username: params[:assignee_username])
else else
nil nil
end end
end end
def author? def author_id?
params[:author_id].present? params[:author_id].present?
end end
def author_username?
params[:author_username].present?
end
def author def author
return @author if defined?(@author) return @author if defined?(@author)
@author = @author =
if author? && params[:author_id] != NONE if author_id? && params[:author_id] != NONE
User.find(params[:author_id]) User.find(params[:author_id])
elsif author_username? && params[:author_username] != NONE
User.find_by(username: params[:author_username])
else else
nil nil
end end
...@@ -263,7 +275,7 @@ class IssuableFinder ...@@ -263,7 +275,7 @@ class IssuableFinder
end end
def by_assignee(items) def by_assignee(items)
if assignee? if assignee_id? || assignee_username?
items = items.where(assignee_id: assignee.try(:id)) items = items.where(assignee_id: assignee.try(:id))
end end
...@@ -271,7 +283,7 @@ class IssuableFinder ...@@ -271,7 +283,7 @@ class IssuableFinder
end end
def by_author(items) def by_author(items)
if author? if author_id? || author_username?
items = items.where(author_id: author.try(:id)) items = items.where(author_id: author.try(:id))
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment