Commit Graph

137 Commits

Author SHA1 Message Date
Nick Thomas d7b03c37f8 Speed up Group#user_ids_for_project_authorizations 2017-08-14 12:47:15 +01:00
Sean McGivern ccac2abeba Don't treat anonymous users as owners when group has pending invites
The `members` table can have entries where `user_id: nil`, because people can
invite group members by email. We never want to include those as members,
because it might cause confusion with the anonymous (logged out) user.
2017-07-24 16:58:04 +01:00
Nick Thomas c9e6caaef4 Promote visibility level helpers from Group to Namespace
In EE, we make use of `namespace#public?` in projects. When the project is in a
personal namespace, this breaks as the `public?` helper isn't present.
2017-07-17 11:54:07 +01:00
Felipe Artur b5f596c3ff Native group milestones 2017-07-07 15:08:49 +00:00
Shinya Maeda 5c68fa66cc secret_variables_for: rails readability versino 2017-07-07 15:35:12 +09:00
Shinya Maeda 5cb45b6a44 Add CASE When Clause for saving order when using where IN 2017-07-07 15:35:12 +09:00
Shinya Maeda bd846f7d93 Use ancestors for avoiding N queries 2017-07-07 15:35:12 +09:00
Shinya Maeda 5b0954759c Basic BE change
Fix static-snalysis

Move the precedence of group secure variable before project secure variable. Allow project_id to be null.

Separate Ci::VariableProject and Ci::VariableGroup

Add the forgotton files

Add migration file to update type of ci_variables

Fix form_for fpr VariableProject

Fix test

Change the table structure according to the yorik advice

Add necessary migration files. Remove unnecessary migration spec.

Revert safe_model_attributes.yml

Fix models

Fix spec

Avoid self.variable. Use becomes for correct routing.

Use unique index on group_id and key

Add null: false for t.timestamps

Fix schema version

Rename VariableProject and VariableGroup to ProjectVariable and GroupVariable

Rename the rest of them

Add the rest of files

Basic BE change

Fix static-snalysis

Move the precedence of group secure variable before project secure variable. Allow project_id to be null.

Separate Ci::VariableProject and Ci::VariableGroup

Add the forgotton files

Add migration file to update type of ci_variables

Fix form_for fpr VariableProject

Fix test

Change the table structure according to the yorik advice

Add necessary migration files. Remove unnecessary migration spec.

Revert safe_model_attributes.yml

Fix models

Fix spec

Avoid self.variable. Use becomes for correct routing.

Use unique index on group_id and key

Add null: false for t.timestamps

Fix schema version

Rename VariableProject and VariableGroup to ProjectVariable and GroupVariable

Rename the rest of them

Add the rest of files

Implement CURD

Rename codes related to VariableGroup and VariableProject FE part

Remove unneccesary changes

Make Fe code up-to-date

Add protected flag to migration file

Protected group variables essential package

Update schema

Improve doc

Fix logic and spec for models

Fix logic and spec for controllers

 Fix logic and spec for views(pre feature)

Add feature spec

Fixed bugs. placeholder. reveal button. doc.

Add changelog

Remove unnecessary comment

godfat nice catches

Improve secret_variables_for arctecture

Fix spec

Fix StaticAnlysys & path_regex spec

Revert "Improve secret_variables_for arctecture"

This reverts commit c3216ca212322ecf6ca534cb12ce75811a4e77f1.

Use ayufan suggestion for secret_variables_for

Use find instead of find_by

Fix spec message for variable is invalid

Fix spec remove variable.group_id = group.id

godffat spec nitpicks

Use include Gitlab::Routing.url_helpers for presenter spec
2017-07-07 15:33:17 +09:00
Yorick Peterse 8fbbf41e29
Added Cop to blacklist the use of `dependent:`
This is allowed for existing instances so we don't end up 76 offenses
right away, but for new code one should _only_ use this if they _have_
to remove non database data. Even then it's usually better to do this in
a service class as this gives you more control over how to remove the
data (e.g. in bulk).
2017-07-06 12:01:36 +02:00
Oswaldo Ferreira da3e4f4128 Add "members_count" and "parent_id" data on namespaces API 2017-06-28 15:50:29 -03:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Sean McGivern 5db229fb45 Allow group reporters to manage group labels
Previously, only group masters could do this. However, project reporters can
manage project labels, so there doesn't seem to be any need to restrict group
labels further.

Also, save a query or two by getting a single GroupMember object to find out if
the user is a master or not.
2017-06-05 11:58:53 +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
blackst0ne 29a3203b3f Use relative paths for group/project/user avatars 2017-05-10 15:26:17 +11:00
Dmitriy Zaporozhets c6960ded8a
Refactor add_users method for project and group
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-04-21 18:38:10 +03:00
Markus Koller a3430f011f Support 2FA requirement per-group 2017-04-06 10:01:13 +02:00
Dmitriy Zaporozhets e8942846c6 Hide ancestor groups in the share group dropdown list
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-03-21 11:00:06 +02:00
Douwe Maan d617182a1a Merge branch 'master' into 'rs-carrierwave-db'
# Conflicts:
#   spec/models/group_spec.rb
2017-03-06 21:13:27 +00:00
Robert Speicher 23c2b8f6bb Add `has_many` associations for models that can have Upload records 2017-03-06 14:41:10 -05:00
Z.J. van de Weg 449ecd6c68 Merge branch 'master' into zj-create-mattermost-team 2017-03-06 08:55:35 +01:00
Toon Claes a3fdd6acd2 Use string based `visibility` getter & setter
Add `visibility` & `visibility=` methods to the
`Gitlab::VisibilityLevel` module so the `visibility_level` can be
get/set with a string value.
2017-03-02 12:15:25 +01:00
Z.J. van de Weg 52c4a7866e Improve UX 2017-03-02 10:21:29 +01:00
Z.J. van de Weg 444d71e043 Transactional mattermost team creation
Before this commit, but still on this feature branch, the creation of
mattermost teams where a background job. However, it was decided it was
better that these happened as transaction so feedback could be displayed
to the user.
2017-02-20 13:41:50 +01:00
Z.J. van de Weg 297dc70158 Create MM team for GitLab group 2017-02-16 09:17:40 +01:00
Dmitriy Zaporozhets 2c55fd0019 Add GFM support to nested groups
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-02-13 22:30:10 +02:00
Dmitriy Zaporozhets 5f85487c15
Show parent group members for nested group
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-02-10 17:34:12 +02:00
Yorick Peterse ebae38394d
Refresh authorizations when transferring projects
This ensures that project authorizations are refreshed when moving a
project from one namespace to another. When doing so the permissions for
all users of both the old and new namespaces are refreshed.

See #26194 for more information.
2017-02-07 14:58:49 +01:00
Dmitriy Zaporozhets 51c4b20c48 Refactor Namespace code related to nested groups
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-01-13 10:05:02 -05:00
James Lopez 112f470572 Fix cross-project references copy to include the project reference
Also added relevant specs and refactored to_references in a bunch of places to be more consistent.
2017-01-03 13:01:46 +01:00
Dmitriy Zaporozhets c595b41881 Merge branch 'dz-nested-group-access' into 'master'
Inherit permissions from parent group

See merge request !8071
2016-12-29 00:00:10 +00:00
Dmitriy Zaporozhets 9f39953eaf
Improve Group#users_with_parents method
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-29 00:29:33 +02:00
Dmitriy Zaporozhets 7b4b3d5f26 Include group parents into read access for project and group
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-26 10:57:11 +02:00
Markus Koller 3ef4f74b1a
Add more storage statistics
This adds counters for build artifacts and LFS objects, and moves
the preexisting repository_size and commit_count from the projects
table into a new project_statistics table.

The counters are displayed in the administration area for projects
and groups, and also available through the API for admins (on */all)
and normal users (on */owned)

The statistics are updated through ProjectCacheWorker, which can now
do more granular updates with the new :statistics argument.
2016-12-21 16:39:49 +01:00
Dmitriy Zaporozhets 78115dc13a
Use full_name for Group in UI
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-13 17:00:06 +02:00
Ahmad Sherif 0f3c3a1c57 Update user's authorized projects if project is allowed to share with group 2016-11-23 12:59:07 +02:00
Ahmad Sherif 4262687a97 Use the minimum access level of group link and group member when inserting authorized project records 2016-11-23 12:57:54 +02:00
Ahmad Sherif fd05e26618 Precalculate user's authorized projects in database
Closes #23150
2016-11-18 20:25:45 +02:00
Dmitriy Zaporozhets 3be445c58e Revert "Revert "Change "Group#web_url" to return "/groups/twitter" rather than "/twitter".""
This reverts commit 9dbd5b3cfa.
2016-10-27 16:16:15 +03:00
David Wagner 03b6108f6f Remove redundant class_name and foreign_key overrides
They were Rails' default and are unnecessarily overridden.

Signed-off-by: David Wagner <david@marvid.fr>
2016-10-24 22:29:48 +02:00
Dmitriy Zaporozhets 9dbd5b3cfa Revert "Change "Group#web_url" to return "/groups/twitter" rather than "/twitter"."
This reverts commit c81ff152e0.
2016-10-24 13:14:00 +03:00
Adam Niedzielski c81ff152e0 Change "Group#web_url" to return "/groups/twitter" rather than "/twitter".
Bring back the old behaviour which was changed by 6b90ccb9.
Fixes #23527.
2016-10-21 13:53:38 +02:00
Douglas Barbosa Alexandre d820c090ec Add GroupLabel model 2016-10-19 14:57:14 -02:00
Rémy Coutable ec0061a95c Allow Member.add_user to handle access requesters
Changes include:

- Ensure Member.add_user is not called directly when not necessary
- New GroupMember.add_users_to_group to have the same abstraction level as for Project
- Refactor Member.add_user to take a source instead of an array of members
- Fix Rubocop offenses
- Always use Project#add_user instead of project.team.add_user
- Factorize users addition as members in Member.add_users_to_source
- Make access_level a keyword argument in GroupMember.add_users_to_group and ProjectMember.add_users_to_projects
- Destroy any requester before adding them as a member
- Improve the way we handle access requesters in Member.add_user
  Instead of removing the requester and creating a new member,
  we now simply accepts their access request. This way, they will
  receive a "access request granted" email.
- Fix error that was previously silently ignored
- Stop raising when access level is invalid in Member, let Rails validation do their work

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-09-28 09:43:00 +02:00
Patricio Cano fd62142950 Added group-specific setting for LFS.
Groups can enable/disable LFS, but this setting can be overridden at the project level. Admin only
2016-09-15 12:27:32 -05:00
Sean McGivern 396f85e438 Add expiration date to group memberships 2016-08-18 21:09:17 +01:00
Adam Niedzielski b2c8dc6f35 Replace optional parameters with keyword arguments. 2016-08-02 20:37:22 +02:00
Robert Speicher c7b68b6e66 Dumb-down avatar presence check in `avatar_url` methods
`avatar.present?` goes through CarrierWave, and checks that the file
exists on disk and checks its filesize. Because we're hitting the disk,
this adds extra overhead to something where the worst-case scenario is
rendering a broken image.

Instead, we now just check that the _database attribute_ is present,
which is good enough for our purposes.

See https://gitlab.com/gitlab-org/gitlab-ce/issues/19273
2016-07-05 10:51:11 -04:00
Rémy Coutable bd78f5733c Exclude requesters from Project#members, Group#members and User#members
And create new Project#requesters, Group#requesters scopes.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-07-01 17:44:46 +02:00
Rémy Coutable aec3475df9
Fix an information disclosure when requesting access to a group containing private projects
The issue was with the `User#groups` and `User#projects` associations
which goes through the `User#group_members` and `User#project_members`.

Initially I chose to use a secure approach by storing the requester's
user ID in `Member#created_by_id` instead of `Member#user_id` because I
was aware that there was a security risk since I didn't know the
codebase well enough.

Then during the review, we decided to change that and directly store the
requester's user ID into `Member#user_id` (for the sake of simplifying
the code I believe), meaning that every `group_members` / `project_members`
association would include the requesters by default...

My bad for not checking that all the `group_members` / `project_members`
associations and the ones that go through them (e.g. `Group#users` and
`Project#users`) were made safe with the `where(requested_at: nil)` /
`where(members: { requested_at: nil })` scopes.

Now they are all secure.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-06-24 12:01:48 +02:00
Yorick Peterse 84e2be5a5f
Turn Group#owners into a has_many association
This allows the owners to be eager loaded where needed.
2016-06-16 11:10:41 +02:00