Commit Graph

68 Commits

Author SHA1 Message Date
GitLab Bot 4ecd816dcb Add latest changes from gitlab-org/gitlab@master 2023-12-21 09:17:08 +00:00
GitLab Bot cf66f24775 Add latest changes from gitlab-org/gitlab@master 2023-10-10 00:12:47 +00:00
GitLab Bot 4d18bba787 Add latest changes from gitlab-org/gitlab@master 2023-08-07 18:10:22 +00:00
GitLab Bot 9979d2afd6 Add latest changes from gitlab-org/gitlab@master 2023-07-27 15:10:15 +00:00
GitLab Bot 0624f8b515 Add latest changes from gitlab-org/gitlab@master 2023-07-20 03:08:56 +00:00
GitLab Bot fe530c6e7f Add latest changes from gitlab-org/gitlab@master 2023-06-16 21:09:11 +00:00
GitLab Bot bdad4dd5da Add latest changes from gitlab-org/gitlab@master 2023-06-06 00:08:24 +00:00
GitLab Bot fc4faf47ac Add latest changes from gitlab-org/gitlab@master 2023-05-25 12:07:22 +00:00
GitLab Bot 709948b7a6 Add latest changes from gitlab-org/gitlab@master 2023-01-20 15:08:53 +00:00
GitLab Bot e129eff883 Add latest changes from gitlab-org/gitlab@master 2022-07-05 18:08:43 +00:00
GitLab Bot 48d9e7ff8d Add latest changes from gitlab-org/gitlab@master 2022-05-12 03:08:58 +00:00
GitLab Bot bf1a77ead7 Add latest changes from gitlab-org/gitlab@master 2022-02-23 06:18:49 +00:00
GitLab Bot 78cfc7cf4a Add latest changes from gitlab-org/gitlab@master 2022-02-15 15:15:04 +00:00
GitLab Bot e7e44c0e4c Add latest changes from gitlab-org/gitlab@master 2022-02-15 09:17:01 +00:00
GitLab Bot 2b2d833ab3 Add latest changes from gitlab-org/gitlab@master 2022-01-25 18:11:55 +00:00
GitLab Bot 6b5937e93e Add latest changes from gitlab-org/gitlab@master 2022-01-20 09:11:11 +00:00
GitLab Bot 1c27dcaf69 Add latest changes from gitlab-org/gitlab@master 2021-11-24 00:12:33 +00:00
GitLab Bot e5d3d8c323 Add latest changes from gitlab-org/gitlab@master 2021-10-25 12:10:19 +00:00
GitLab Bot 7134e029c5 Add latest changes from gitlab-org/gitlab@master 2021-08-13 15:11:15 +00:00
GitLab Bot c4af99d56f Add latest changes from gitlab-org/gitlab@master 2021-07-26 12:10:08 +00:00
GitLab Bot b7b1a593e4 Add latest changes from gitlab-org/gitlab@master 2021-05-03 18:10:17 +00:00
GitLab Bot 6de7d2c195 Add latest changes from gitlab-org/gitlab@master 2020-09-16 15:09:32 +00:00
GitLab Bot c59765a50a Add latest changes from gitlab-org/gitlab@master 2020-06-24 18:09:03 +00:00
GitLab Bot 6b7b853dff Add latest changes from gitlab-org/gitlab@master 2020-06-03 06:08:34 +00:00
GitLab Bot d2ffc30fd5 Add latest changes from gitlab-org/gitlab@master 2019-10-16 12:06:32 +00:00
Rémy Coutable f3ad4ecb73
[CE] Reduce diff with EE in spec/models/project_team_spec.rb
Signed-off-by: Rémy Coutable <remy@rymai.me>
2019-04-02 10:21:35 +02:00
Thong Kuah a2cfc150ce Add # frozen_string_literal to spec/models
Adds `# frozen_string_literal: true` to spec/models ruby files
2019-04-01 14:37:54 +13:00
Jan Provaznik 4d7fa59af2
Sent notification only to authorized users
When moving a project, it's possible that some users who had
access to the project in old path can not access the project
in the new path.

Because `project_authorizations` records are updated asynchronously,
when we send the notification about moved project the list of project
team members contains old project members, we want to notify all these
members except the old users who can not access the new location.
2019-01-31 16:52:49 +01:00
Mark Chao a63bce1a4b Resolve "Rename the `Master` role to `Maintainer`" Backend 2018-07-11 14:36:08 +00:00
Mark Chao 7c965a24f5 Fix spec 2018-06-06 20:57:15 +09:00
blackst0ne 27c95364b5 Replace '.team << [user, role]' with 'add_role(user)' in specs 2017-12-22 19:18:28 +11: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
Rémy Coutable ddccd24c13 Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-07-27 14:31:53 +02:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Robert Speicher a6ec5121f0 Correct RSpec/SingleLineHook cop offenses 2017-06-14 13:18:56 -05:00
Oswaldo Ferreira 34ba80392d Use :request_store hooks on specs 2017-06-09 18:18:36 -03:00
Sean McGivern 7f73f440f9 Fix N+1 queries for non-members in comment threads
When getting the max member access for a group of users, we stored the results
in RequestStore. However, this will only return results for project members, so
anyone who wasn't a member of the project would be checked once at the start,
and then once for each comment they made. These queries are generally quite
fast, but no query is faster!
2017-06-01 10:21:26 +01: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 fcb37542e7 Use `:empty_project` where possible in model specs 2017-01-26 17:44:59 -05:00
Ahmad Sherif 2ea5ef0ba4 Update ProjectTeam#fetch_members to use project authorizations 2016-11-23 12:59:13 +02:00
Ahmad Sherif 747959a832 Update ProjectTeam#max_member_access_for_user_ids to use project authorizations 2016-11-23 12:59:13 +02:00
Ahmad Sherif 916332815e Drop Project#authorized_for_user? in favor of ProjectTeam#member?
Closes #23938
2016-11-23 12:57:58 +02:00
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
Nick Thomas d211011698 Make access request specs explicitly enable or disable access requests as required 2016-11-11 15:45:47 +00:00
Rémy Coutable 178e2758f6 Fix specs that requires an access request
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-09-22 11:12:17 +02:00
Robert Speicher 6f558121b4 Fix a logic error in ProjectTeam#fetch_invited_members
We were calling `.where` and `.send` on the relation, but never doing
anything with the return value, resulting in proper access-level
filtering never being of any consequence.
2016-09-20 21:48:58 +03:00
Robert Speicher b674ab529a Add specs for ProjectTeam#fetch_members 2016-09-20 15:18:11 +03:00
Stan Hu 99c02ed53c Only use RequestStore in ProjectTeam#max_member_access_for_user if it is active 2016-08-01 13:11:45 -07:00
Stan Hu ba192c73cd Rubocop offenses 2016-07-26 17:05:52 -07:00