BigW Consortium Gitlab

Commit 8724d587 by Regis

Merge branch 'master' into auto-pipelines-vue

parents 1c85514a 5368b9f2
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
$dropdown = $(dropdown); $dropdown = $(dropdown);
options.projectId = $dropdown.data('project-id'); options.projectId = $dropdown.data('project-id');
options.showCurrentUser = $dropdown.data('current-user'); options.showCurrentUser = $dropdown.data('current-user');
options.todoFilter = $dropdown.data('todo-filter');
options.todoStateFilter = $dropdown.data('todo-state-filter');
showNullUser = $dropdown.data('null-user'); showNullUser = $dropdown.data('null-user');
showMenuAbove = $dropdown.data('showMenuAbove'); showMenuAbove = $dropdown.data('showMenuAbove');
showAnyUser = $dropdown.data('any-user'); showAnyUser = $dropdown.data('any-user');
...@@ -394,6 +396,8 @@ ...@@ -394,6 +396,8 @@
project_id: options.projectId || null, project_id: options.projectId || null,
group_id: options.groupId || null, group_id: options.groupId || null,
skip_ldap: options.skipLdap || null, skip_ldap: options.skipLdap || null,
todo_filter: options.todoFilter || null,
todo_state_filter: options.todoStateFilter || null,
current_user: options.showCurrentUser || null, current_user: options.showCurrentUser || null,
push_code_to_protected_branches: options.pushCodeToProtectedBranches || null, push_code_to_protected_branches: options.pushCodeToProtectedBranches || null,
author_id: options.authorId || null, author_id: options.authorId || null,
......
...@@ -11,9 +11,13 @@ class AutocompleteController < ApplicationController ...@@ -11,9 +11,13 @@ class AutocompleteController < ApplicationController
@users = @users.reorder(:name) @users = @users.reorder(:name)
@users = @users.page(params[:page]) @users = @users.page(params[:page])
if params[:todo_filter].present?
@users = @users.todo_authors(current_user.id, params[:todo_state_filter])
end
if params[:search].blank? if params[:search].blank?
# Include current user if available to filter by "Me" # Include current user if available to filter by "Me"
if params[:current_user] && current_user if params[:current_user].present? && current_user
@users = [*@users, current_user] @users = [*@users, current_user]
end end
......
...@@ -173,6 +173,7 @@ class User < ActiveRecord::Base ...@@ -173,6 +173,7 @@ class User < ActiveRecord::Base
scope :active, -> { with_state(:active) } scope :active, -> { with_state(:active) }
scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all } scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all }
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') } scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') }
scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) }
def self.with_two_factor def self.with_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"). joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id").
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
- if params[:author_id].present? - if params[:author_id].present?
= hidden_field_tag(:author_id, params[:author_id]) = hidden_field_tag(:author_id, params[:author_id])
= dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#author-search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit', = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#author-search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit',
placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author' } }) placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author', todo_filter: true, todo_state_filter: params[:state] || 'pending' } })
.filter-item.inline .filter-item.inline
- if params[:type].present? - if params[:type].present?
= hidden_field_tag(:type, params[:type]) = hidden_field_tag(:type, params[:type])
......
---
title: 'Fix: Todos Filter Shows All Users'
merge_request:
author:
module API module API
# Projects API # Projects API
class ProjectHooks < Grape::API class ProjectHooks < Grape::API
helpers do
params :project_hook_properties do
requires :url, type: String, desc: "The URL to send the request to"
optional :push_events, type: Boolean, desc: "Trigger hook on push events"
optional :issues_events, type: Boolean, desc: "Trigger hook on issues events"
optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events"
optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
optional :note_events, type: Boolean, desc: "Trigger hook on note(comment) events"
optional :build_events, type: Boolean, desc: "Trigger hook on build events"
optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events"
optional :wiki_events, type: Boolean, desc: "Trigger hook on wiki events"
optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
optional :token, type: String, desc: "Secret token to validate received payloads; this will not be returned in the response"
end
end
before { authenticate! } before { authenticate! }
before { authorize_admin_project } before { authorize_admin_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do resource :projects do
# Get project hooks desc 'Get project hooks' do
# success Entities::ProjectHook
# Parameters: end
# id (required) - The ID of a project
# Example Request:
# GET /projects/:id/hooks
get ":id/hooks" do get ":id/hooks" do
@hooks = paginate user_project.hooks hooks = paginate user_project.hooks
present @hooks, with: Entities::ProjectHook
present hooks, with: Entities::ProjectHook
end end
# Get a project hook desc 'Get a project hook' do
# success Entities::ProjectHook
# Parameters: end
# id (required) - The ID of a project params do
# hook_id (required) - The ID of a project hook requires :hook_id, type: Integer, desc: 'The ID of a project hook'
# Example Request: end
# GET /projects/:id/hooks/:hook_id
get ":id/hooks/:hook_id" do get ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id]) hook = user_project.hooks.find(params[:hook_id])
present @hook, with: Entities::ProjectHook present hook, with: Entities::ProjectHook
end end
# Add hook to project desc 'Add hook to project' do
# success Entities::ProjectHook
# Parameters: end
# id (required) - The ID of a project params do
# url (required) - The hook URL use :project_hook_properties
# Example Request: end
# POST /projects/:id/hooks
post ":id/hooks" do post ":id/hooks" do
required_attributes! [:url] new_hook_params = declared(params, include_missing: false, include_parent_namespaces: false).to_h
attrs = attributes_for_keys [ hook = user_project.hooks.new(new_hook_params)
:url,
:push_events,
:issues_events,
:merge_requests_events,
:tag_push_events,
:note_events,
:build_events,
:pipeline_events,
:wiki_page_events,
:enable_ssl_verification,
:token
]
@hook = user_project.hooks.new(attrs)
if @hook.save if hook.save
present @hook, with: Entities::ProjectHook present hook, with: Entities::ProjectHook
else else
if @hook.errors[:url].present? error!("Invalid url given", 422) if hook.errors[:url].present?
error!("Invalid url given", 422)
end not_found!("Project hook #{hook.errors.messages}")
not_found!("Project hook #{@hook.errors.messages}")
end end
end end
# Update an existing project hook desc 'Update an existing project hook' do
# success Entities::ProjectHook
# Parameters: end
# id (required) - The ID of a project params do
# hook_id (required) - The ID of a project hook requires :hook_id, type: Integer, desc: "The ID of the hook to update"
# url (required) - The hook URL use :project_hook_properties
# Example Request: end
# PUT /projects/:id/hooks/:hook_id
put ":id/hooks/:hook_id" do put ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id]) hook = user_project.hooks.find(params[:hook_id])
required_attributes! [:url]
attrs = attributes_for_keys [ new_params = declared(params, include_missing: false, include_parent_namespaces: false).to_h
:url, new_params.delete('hook_id')
:push_events,
:issues_events,
:merge_requests_events,
:tag_push_events,
:note_events,
:build_events,
:pipeline_events,
:wiki_page_events,
:enable_ssl_verification,
:token
]
if @hook.update_attributes attrs if hook.update_attributes(new_params)
present @hook, with: Entities::ProjectHook present hook, with: Entities::ProjectHook
else else
if @hook.errors[:url].present? error!("Invalid url given", 422) if hook.errors[:url].present?
error!("Invalid url given", 422)
end not_found!("Project hook #{hook.errors.messages}")
not_found!("Project hook #{@hook.errors.messages}")
end end
end end
# Deletes project hook. This is an idempotent function. desc 'Deletes project hook' do
# success Entities::ProjectHook
# Parameters: end
# id (required) - The ID of a project params do
# hook_id (required) - The ID of hook to delete requires :hook_id, type: Integer, desc: 'The ID of the hook to delete'
# Example Request: end
# DELETE /projects/:id/hooks/:hook_id
delete ":id/hooks/:hook_id" do delete ":id/hooks/:hook_id" do
required_attributes! [:hook_id]
begin begin
@hook = user_project.hooks.destroy(params[:hook_id]) present user_project.hooks.destroy(params[:hook_id]), with: Entities::ProjectHook
rescue rescue
# ProjectHook can raise Error if hook_id not found # ProjectHook can raise Error if hook_id not found
not_found!("Error deleting hook #{params[:hook_id]}") not_found!("Error deleting hook #{params[:hook_id]}")
......
...@@ -36,8 +36,10 @@ describe 'Dashboard > User filters todos', feature: true, js: true do ...@@ -36,8 +36,10 @@ describe 'Dashboard > User filters todos', feature: true, js: true do
expect(page).not_to have_content project_2.name_with_namespace expect(page).not_to have_content project_2.name_with_namespace
end end
context "Author filter" do
it 'filters by author' do it 'filters by author' do
click_button 'Author' click_button 'Author'
within '.dropdown-menu-author' do within '.dropdown-menu-author' do
fill_in 'Search authors', with: user_1.name fill_in 'Search authors', with: user_1.name
click_link user_1.name click_link user_1.name
...@@ -49,6 +51,41 @@ describe 'Dashboard > User filters todos', feature: true, js: true do ...@@ -49,6 +51,41 @@ describe 'Dashboard > User filters todos', feature: true, js: true do
expect(find('.todos-list')).not_to have_content user_2.name expect(find('.todos-list')).not_to have_content user_2.name
end end
it "shows only authors of existing todos" do
click_button 'Author'
within '.dropdown-menu-author' do
# It should contain two users + "Any Author"
expect(page).to have_selector('.dropdown-menu-user-link', count: 3)
expect(page).to have_content(user_1.name)
expect(page).to have_content(user_2.name)
end
end
it "shows only authors of existing done todos" do
user_3 = create :user
user_4 = create :user
create(:todo, user: user_1, author: user_3, project: project_1, target: issue, action: 1, state: :done)
create(:todo, user: user_1, author: user_4, project: project_2, target: merge_request, action: 2, state: :done)
project_1.team << [user_3, :developer]
project_2.team << [user_4, :developer]
visit dashboard_todos_path(state: 'done')
click_button 'Author'
within '.dropdown-menu-author' do
# It should contain two users + "Any Author"
expect(page).to have_selector('.dropdown-menu-user-link', count: 3)
expect(page).to have_content(user_3.name)
expect(page).to have_content(user_4.name)
expect(page).not_to have_content(user_1.name)
expect(page).not_to have_content(user_2.name)
end
end
end
it 'filters by type' do it 'filters by type' do
click_button 'Type' click_button 'Type'
within '.dropdown-menu-type' do within '.dropdown-menu-type' do
......
...@@ -256,6 +256,20 @@ describe User, models: true do ...@@ -256,6 +256,20 @@ describe User, models: true do
expect(users_without_two_factor).not_to include(user_with_2fa.id) expect(users_without_two_factor).not_to include(user_with_2fa.id)
end end
end end
describe '.todo_authors' do
it 'filters users' do
create :user
user_2 = create :user
user_3 = create :user
current_user = create :user
create(:todo, user: current_user, author: user_2, state: :done)
create(:todo, user: current_user, author: user_3, state: :pending)
expect(User.todo_authors(current_user.id, 'pending')).to eq [user_3]
expect(User.todo_authors(current_user.id, 'done')).to eq [user_2]
end
end
end end
describe "Respond to" do describe "Respond to" do
......
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