Commit Graph

308 Commits

Author SHA1 Message Date
Michael Kozono bd578d96b4 Add namespace errors from User#after_update 2017-08-18 10:31:59 -07:00
Michael Kozono 82bafd002d Make username update fail if namespace part fails 2017-08-17 13:18:02 -07:00
Yorick Peterse 0395c47193
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".

This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.

The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").

== Newly Created Events

Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.

This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.

== Supporting Both Old And New Events

Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.

Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.

The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.

== API Changes

The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-08-10 17:45:44 +02:00
Michael Kozono 255be6c5ca Prevent user from changing username with container registry tags 2017-08-09 16:24:49 +00:00
Yorick Peterse ab738645a7
Memoize a user's personal projects count
The method User#projects_limit_left would run "personal_projects.count"
but such a query is not memoized. As a result multiple calls to
User#projects_limit_left would result in multiple COUNT(*) queries being
executed.

To work around this this commit adds User#personal_projects_count which
simply memoizes the result of the COUNT(*) in an instance variable.
2017-08-07 12:38:32 +02:00
Robert Speicher 72a7b30c9f Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
Dmitriy Zaporozhets ac0cbe6970 Merge branch 'feature/gpg-signed-commits' into 'master'
GPG signed commits

Closes #20268

See merge request !9546
2017-07-27 15:29:39 +00:00
Alexis Reigel e75ab06430 update invalid gpg signatures when email changes 2017-07-27 15:42:53 +02:00
Alexis Reigel 7e13d96715 don't sync to keychain file 2017-07-27 15:42:53 +02:00
Alexis Reigel 8bd94a7304 remove gpg from keychain when user's email changes 2017-07-27 15:42:04 +02:00
Rémy Coutable cddc5cacfb Use described_class when possible
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-07-27 14:31:53 +02: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
Dmitriy Zaporozhets 3a0b9e06e1
Adjust tests to work with latest shoulda gem
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-07-24 19:26:15 +03:00
Bob Van Landuyt 458f3cf9b0 Update specs for new upload path 2017-07-18 15:38:54 +02:00
Tiago Botelho 574b3efd6b Fixes the user order being overriden in the autocomplete controller 2017-07-14 16:31:45 +01:00
Sean McGivern 1afdbe320e Merge branch 'fixes-for-internal-auth-disabled' into 'master'
Fixes needed when GitLab sign-in is not enabled

See merge request !12491
2017-07-14 08:49:36 +00:00
Robin Bobbitt 672a68d372 Fixes needed when GitLab sign-in is not enabled
When sign-in is disabled:
 - skip password expiration checks
 - prevent password reset requests
 - don’t show Password tab in User Settings
 - don’t allow login with username/password for Git over HTTP requests
 - render 404 on requests to Profiles::PasswordsController
2017-07-13 10:08:27 -04:00
Nathan Neulinger 4f47de62b4 Stop sanitizing user 'name' when inserting into db
Add spec tests for encoding
2017-07-12 07:48:48 -05:00
Paul Charlton cb3b4a15e6 Support multiple Redis instances based on queue type 2017-07-11 03:35:47 +00:00
Tiago Botelho 199425cee6 Inserts exact matches of username, email and name to the top of the user search list 2017-06-29 10:02:41 +01:00
Toon Claes b90f1098cf Add User#full_private_access? to check if user has Private access
In CE only the admin has access to all private groups & projects. In EE also an
auditor can have full private access.

To overcome merge conflicts, or accidental incorrect access rights, abstract
this out in `User#full_private_access?`.

`User#admin?` now only should be used for admin-only features. For private
access-related features `User#full_private_access?` should be used.

Backported from gitlab-org/gitlab-ee!2199
2017-06-23 11:15:35 +02:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Douwe Maan 757c537fbc Merge branch '30725-reset-user-limits-when-unchecking-external-user' into 'master'
Ensures default user limits when external user is unchecked

Closes #30725

See merge request !12218
2017-06-19 16:33:28 +00:00
Tiago Botelho 4449f57ea6 refactors user model validations 2017-06-19 15:48:24 +01:00
Tiago Botelho db33c0fb63 Ensures default user limits when external user is unchecked 2017-06-16 19:26:04 +01:00
Robert Speicher a6ec5121f0 Correct RSpec/SingleLineHook cop offenses 2017-06-14 13:18:56 -05:00
DJ Mountney 1d1363e2bb Bring in security changes from the 9.2.5 release
Ran:
 - git format-patch v9.2.2..v9.2.5 --stdout > patchfile.patch
 - git checkout -b 9-2-5-security-patch origin/v9.2.2
 - git apply patchfile.patch
 - git commit
 - [Got the sha ref for the commit]
 - git checkout -b upstream-9-2-security master
 - git cherry-pick <SHA of the patchfile commit>
 - [Resolved conflicts]
 - git cherry-pick --continue
2017-06-07 21:16:20 -07:00
Lin Jen-Shin d919f924bf Backport https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1942 2017-06-06 21:42:45 +08:00
Nick Thomas 7db09c63cc Fix hard-deleting users when they have authored issues 2017-06-02 02:06:56 +01:00
Toon Claes 1e5506d016 Remove some deprecated methods
To avoid the use of slow queries, remove some deprecated methods and encourage
the use of ProjectFinder to find projects.
2017-05-30 23:24:17 +02: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
Alexis Reigel 2f277d10ac ensure rss token on read
we do this on attribute read since migrating all existing users is not a
feasible solution.
2017-05-24 22:29:59 +02:00
Alexis Reigel c1b5c8069e add missing spec for incoming email token presence 2017-05-24 22:29:59 +02:00
Alexis Reigel 3713a57fe8 add rss_token attribute to user model 2017-05-24 22:29:59 +02:00
Michael Kozono 8d4cc9cbe0 Fixes #32474
Older namespace records may be both `type == ‘Group` AND `owner_id` is not null.
2017-05-17 17:12:09 -07: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
Valery Sizov a6c0eb54dc Invalidate cache for issue and MR counters more granularly 2017-05-15 22:51:53 +03:00
Rémy Coutable d40e1f547e Enable the Style/TrailingCommaInLiteral cop
Use the EnforcedStyleForMultiline: no_comma option.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-05-10 18:25:45 +02:00
blackst0ne 29a3203b3f Use relative paths for group/project/user avatars 2017-05-10 15:26:17 +11:00
Toon Claes 3531ea096f Devise can assign trackable fields, but only allow writes once/hour
Not assigning the trackable fields seems to cause strange side-effects.
2017-05-08 08:48:38 +02:00
Toon Claes 6a915d6f2d Limit `update_tracked_fields` to write to database once/hour
Every time a user logs in or out, the Trackable attributes are written to the
database. This is causing a lot of load on the database, for data that isn't
really critical.

So to avoid the database being hammered, add a Gitlab::ExclusiveLease before
writing trackable attributes to the database. This lease expires after an hour,
so only when the attributes were written more than an hour ago, they can be
written again. Otherwise they are ignored.
2017-05-08 08:48:38 +02:00
Michael Kozono 7d02bcd2e0 Redirect from redirect routes to canonical routes 2017-05-05 12:11:57 -07:00
Robert Speicher c89849af47 Merge branch 'backport-ee-4b464eaaee' into 'master'
Backport avatar-related spec changes from gitlab-org/gitlab-ee@4b464eaaee

See merge request !11072
2017-05-05 14:01:08 +00:00
Ruben Davila b396668ec5 Add CHANGELOG entry, some specs and locale file for German. 2017-05-04 18:44:19 -05:00
Rémy Coutable f1ace97f8b Backport avatar-related spec changes from gitlab-org/gitlab-ee@4b464eaaee
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-05-04 17:04:36 +02:00
Bob Van Landuyt 08b1bc3489 Reject group-routes as names of child namespaces 2017-05-01 11:14:24 +02:00
Douwe Maan b9e573db57 Skip validation when creating internal (ghost, service desk) users 2017-04-26 14:13:13 -05:00
Sean McGivern 33a25e0fc6 Merge branch 'uassign_on_member_removing' into 'master'
Unassign all Issues and Merge Requests when member leaves a team

Closes #30768 and #24117

See merge request !10755
2017-04-20 12:42:41 +00:00
James Lopez 4190146110 Fix active user count 2017-04-19 12:11:04 +02:00
Valery Sizov 59a330f4cd Remove assigned_(issues|merge_requests) methods from the issuable 2017-04-18 21:07:45 +03:00