Commit Graph

41 Commits

Author SHA1 Message Date
Hiroyuki Sato de784ac105 Filter merge requests by target branch 2019-03-09 12:22:58 +00:00
blackst0ne b44a2c801a Update specs to rails5 format
Updates specs to use new rails5 format.

The old format:
`get :show, { some: params }, { some: headers }`

The new format:
`get :show, params: { some: params }, headers: { some: headers }`
2018-12-19 10:04:31 +11:00
Yorick Peterse 6f3c490107
Refactor AutocompleteController
This refactors the AutocompleteController according to the guidelines
and boundaries discussed in
https://gitlab.com/gitlab-org/gitlab-ce/issues/49653. Specifically,
ActiveRecord logic is moved to different finders, which are then used in
the controller. View logic in turn is moved to presenters, instead of
directly using ActiveRecord's "to_json" method.

The finder MoveToProjectFinder is also adjusted according to the
abstraction guidelines and boundaries, resulting in a much more simple
finder.

By using finders (and other abstractions) more actively, we can push a
lot of logic out of the controller. We also remove the need for various
"before_action" hooks, though this could be achieved without using
finders as well.

The various finders related to AutcompleteController have also been
moved into a namespace. This removes the need for calling everything
"AutocompleteSmurfFinder", instead you can use
"Autocomplete::SmurfFinder".
2018-08-20 13:53:00 +02:00
Mark Chao a63bce1a4b Resolve "Rename the `Master` role to `Maintainer`" Backend 2018-07-11 14:36:08 +00:00
Dmitriy Zaporozhets 9fb733c323
Revert few more broken specs related to *_with_namespace methods
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2018-03-05 18:25:52 +02:00
Dmitriy Zaporozhets 8fe9995f11
Replace deprecated name_with_namespace with full_name in app and spec
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2018-03-05 16:15:26 +02:00
Yorick Peterse d2e43fbde6
Removed pagination from AutocompleteUsersFinder
The frontend code doesn't use this so there's no practical point in
supporting this. We also hardcode the limit to 20 so users can no longer
request their own limit, which could overload the database (depending on
any upper bounds perhaps enforced by Kaminari).
2018-02-22 18:55:36 +01:00
Jacopo 2f40dac352 Refactor `have_http_status` into `have_gitlab_http_status` in the specs 2017-10-20 10:13:18 +02:00
Eric Eastwood 90c60138db Move "Move to different project" to sidebar
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/34261
2017-09-03 22:03:17 -05:00
Hiroyuki Sato 7187395ef1 Add filter by my reaction 2017-08-30 07:48:55 +00:00
Robert Speicher c8b802471b Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
Rémy Coutable ebf5a0bd1b
Fix and improve spec/controllers/autocomplete_controller_spec.rb
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-08-10 09:45:03 +02:00
Robert Speicher 72a7b30c9f Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
Robert Speicher 9513bd18c4 Ensure all project factories use `:repository` trait or `:empty_project` 2017-08-01 14:51:52 -04:00
Tiago Botelho 574b3efd6b Fixes the user order being overriden in the autocomplete controller 2017-07-14 16:31:45 +01:00
Robert Speicher a6ec5121f0 Correct RSpec/SingleLineHook cop offenses 2017-06-14 13:18:56 -05:00
DJ Mountney 982368dc55 Merge branch 'dz-restrict-autocomplete' into 'security-9-1'
Allow users autocomplete by author_id only for authenticated users

See merge request !2100
2017-06-08 09:52:27 -07:00
Douwe Maan 26bcef97d6 Merge branch 'rework-authorizations-performance' into 'master'
Rework project authorizations and nested groups for better performance

See merge request !10885
2017-05-29 15:49:56 +00:00
Clement Ho 2339bef1bc Add per page to user autocomplete 2017-05-26 12:59:00 -05:00
Yorick Peterse ac382b5682
Use CTEs for nested groups and authorizations
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.

Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.

For project authorizations the logic is split up into two classes:

* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups

Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.

This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:

* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups

Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.

Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.

== On The Fly Refreshing

Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).

This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.

== Spec Changes

This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
2017-05-17 16:51:08 +02:00
Robert Speicher 4642ca6686 Use `empty_project` where possible in controller specs 2017-01-25 17:14:38 -05:00
Semyon Pupkov f5e8337c7b Do not raise error in AutocompleteController#users when not authorized
https://gitlab.com/gitlab-org/gitlab-ce/issues/25031
2016-11-30 10:09:14 +05:00
Timothy Andrew 41bf093662 CE-specific changes gitlab-org/gitlab-ee#1137
- Extract all common {push,merge} access level model code into the
  `ProtectedBranchAccess` module

- Use the HTTP verb to define controller specs
2016-11-29 17:38:45 +05:30
Robert Speicher eef3609123 Add shortcuts for adding users to a project team with a specific role
This also updates _some_ specs to use these new methods, just to serve
as an example for others going forward, but by no means is this
exhaustive.

Original implementations at !5992 and !6012.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/20944
2016-11-18 14:55:04 +02:00
Paco Guzman ff903e6453 Move to project dropdown with infinite scroll for better performance
Use just SQL to check is a user can admin_issue on a project

Using offset pagination instead pages to avoid a count query

Tradeoff

- we duplicate how we check admin_issue in a SQL relation in the Ability class
2016-08-18 15:31:51 +02:00
Paco Guzman 03386633a4 Move to project dropdown with infinite scroll for better performance
Use just SQL to check is a user can admin_issue on a project

Tradeoff

- we duplicate how we check admin_issue in a SQL relation in the Ability class
2016-08-17 07:33:51 +02:00
Sean McGivern dc4de2d8e2 Allow skipping users in autocomplete
Pass an array of user IDs in the `skip_users` param to have them
excluded from the results (unless they are explicitly included through
the `current_user` or `author_id` params).
2016-07-27 14:10:49 +01:00
Z.J. van de Weg abca19da8b Use HTTP matchers if possible 2016-06-27 20:10:42 +02:00
Zeger-Jan van de Weg 33f8b06c39 Merge branch 'master' into assign-to-issuable-opener 2016-04-15 14:38:15 +02:00
Zeger-Jan van de Weg 3339513ca6 Merge branch 'master' into assign-to-issuable-opener 2016-03-29 17:26:59 +02:00
Robert Speicher e6195b859f Merge branch 'fix-autocomplete-spec' into 'master'
Fix volatile spec.

Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/312.

See merge request !206
2016-02-23 10:11:39 +01:00
Zeger-Jan van de Weg 15a6633999 Revert authors ability to assign anyone 2016-02-22 12:50:25 +01:00
Zeger-Jan van de Weg df27b3a174 Issuable can be assigned to author
Closes #9014

The only difference with #9014 is that I thoughed the author should also be
able to assign the issue. If this is unwanted behavior Ill revert it.
2016-02-22 12:10:56 +01:00
Douwe Maan 5a4c56c38d Reduce method complexity in AutocompleteController 2015-11-20 13:49:24 +01:00
Stan Hu 3715a0f29b Fix bug preventing invite by e-mail
This was broken in 70f5291808 as a result of introducing the ability to filter by current user.

Closes #2320
2015-08-21 13:47:56 -07:00
Stan Hu 70f5291808 Always add current user to autocomplete controller to support filter by "Me"
Partial fix #2202
2015-08-06 00:46:14 -07:00
Stan Hu 96644c1fc1 Better handle unknown projects and groups for autocomplete 2015-07-11 06:19:32 -07:00
Stan Hu 0b67d7a0fe Fix user autocomplete for unauthenticated users accessing public projects
Closes #1955
2015-07-10 17:39:58 -07:00
Robert Speicher 5a9ede4721 Update mock and stub syntax for specs 2015-06-22 12:13:46 +02:00
Robert Speicher 422236c71e Change `foo.should` syntax to `expect(foo).to` in specs 2015-06-13 18:37:30 -04:00
Dmitriy Zaporozhets 26053c8705 Add autocomplete controller 2015-03-26 19:06:19 -07:00