Commit Graph

53 Commits

Author SHA1 Message Date
GitLab Bot ebfc70c3df Add latest changes from gitlab-org/gitlab@master 2024-03-06 18:10:52 +00:00
GitLab Bot 6093748e9e Add latest changes from gitlab-org/gitlab@master 2022-04-27 18:10:15 +00:00
GitLab Bot 676109e1b3 Add latest changes from gitlab-org/gitlab@master 2021-03-31 18:09:19 +00:00
GitLab Bot fa6089d8ad Add latest changes from gitlab-org/gitlab@master 2020-12-15 03:10:12 +00:00
GitLab Bot ff06f859cd Add latest changes from gitlab-org/gitlab@master 2020-11-10 15:09:14 +00:00
GitLab Bot 36b0a5b875 Add latest changes from gitlab-org/gitlab@master 2020-07-21 18:09:45 +00:00
GitLab Bot b922b2f47a Add latest changes from gitlab-org/gitlab@master 2020-07-03 12:08:53 +00:00
GitLab Bot dc889678d1 Add latest changes from gitlab-org/gitlab@master 2020-03-12 15:09:39 +00:00
GitLab Bot 2fd92f2dc7 Add latest changes from gitlab-org/gitlab@master 2020-03-04 21:07:54 +00:00
GitLab Bot f8d15ca653 Add latest changes from gitlab-org/gitlab@master 2020-02-27 15:09:24 +00:00
Manoj MJ 53b17f0301 Add documentation and tests
This commit adds
 - feature specs
  - to test the ability of a user with "developer" permission
    to delete tags in repositories.
 - documentation
2019-06-19 07:08:56 +00:00
Patrick Bajao e371520f46 Allow protected branch creation via web and API
This commit includes changes to add `UserAccess#can_create_branch?`
which will check whether the user is allowed to create a branch even
if it matches a protected branch.

This is used in `Gitlab::Checks::BranchCheck` when the branch name
matches a protected branch.

A `push_to_create_protected_branch` ability in `ProjectPolicy` has been
added to allow Developers and above to create protected branches.
2019-03-06 12:20:27 +00:00
gfyoung c858f70d07 Enable frozen string for lib/gitlab/*.rb 2018-10-22 07:00:50 +00:00
Mark Chao 0d44f4d50e Rephrase "maintainer" to more precise "members who can merge to the target branch"
"Maintainer" will be freed to be used for #42751
2018-06-01 14:33:12 +09:00
Bob Van Landuyt 35a49922e6 Allow admins to push to empty repos 2018-04-24 14:06:59 +02:00
Douwe Maan 05732d90da Rename delete_protected_branch ability to push_to_delete_protected_branch to prevent confusion with destroy_protected_branch 2018-04-10 15:46:20 +02:00
Bob Van Landuyt 12e68d6215 Validate `:push_code` before checking protected branches 2018-03-08 00:37:59 +01:00
Bob Van Landuyt 9aabd8fd5e Limit queries to a user-branch combination
The query becomes a lot simpler if we can check the branch name as
well instead of having to load all branch names.
2018-03-07 16:59:17 +01:00
Bob Van Landuyt c9557ad711 Allow maintainers to push to a single branch 2018-03-07 15:12:31 +01:00
Horatiu Eugen Vlad 1ad5df49b1 Moved o_auth/saml/ldap modules under gitlab/auth 2018-02-28 16:53:02 +01:00
Bob Van Landuyt 148816cd67 Port `read_cross_project` ability from EE 2018-02-22 17:11:36 +01:00
Tiago Botelho 1e56b3f476 Moves project creationg to git access check for git push 2018-02-06 16:52:29 +00:00
Lin Jen-Shin 4f00a05152 Introduce PredicateMemoization cop and fix offenses
with StrongMemoize
2018-01-12 17:54:55 +08:00
Lin Jen-Shin d035d73524 Fix tests and fine tweak permission error message 2017-07-19 22:37:38 +08:00
Lin Jen-Shin a397a0eb1a Eliminate N+1 queries on checking different protected refs
I realized where the N+1 queries were actually coming from
project.protected_branches, but how come we cannot preload this,
or cache this at all?

Then I found that this is somehow a Rails limitation. What we're
doing before, eventually come to:

    project.protected_branches.matching

But why it's not cached? (project.protected_branches.loaded? is always
false) It's because matching is a class method, which is called on
the proxy. In this case, Rails cannot cache the result. I don't know
if this is possible to implement or not, because clearly this would
require some tricks to implement class methods on associations.

So instead, we could just pass project.protected_branches to
ProtectedRef.matching, then it would work regularly.

With this change, there's no more N+1 queries.
2017-07-19 19:12:11 +08:00
Lin Jen-Shin 679789ee93 Rename can_push_or_merge_to_branch? to can_update_branch?
Also make sure pipeline would also check against tag as well
2017-07-18 21:56:28 +08:00
Lin Jen-Shin 3c7cb6ad9e Merge remote-tracking branch 'upstream/master' into 30634-protected-pipeline
* upstream/master: (25 commits)
  Remove unneeded asserts and add tests for inactive RequestStore
  Rename the methods to make it fit with current name
  Follow feedback on the merge request
  Make sure it checks against the tag only when it's a tag
  Renamed Gitaly services
  fix transient rspec failure due to Poll.js race condition
  Refactor variables initialization in dropzone_input.js
  cache the cache key...
  avoid #respond_to? in Cache.id_for
  cache DeclarativePolicy.class_for at the class level
  Update 9.3-to-9.4.md
  fix padding on filtered search dropdown. Styles should only apply to li in list
  Cache Note#notable for commits and fix tests
  Add changelog entry
  Update the comments for the new functionality
  Use RequestStoreWrap for Commit#author
  Skip dead jobs queue for web hooks and project services
  Add RequestStoreWrap to cache via RequestStore
  Don't track cached queries in Gitlab::PerformanceBar::PeekQueryTracker
  Add changelog entry
  ...
2017-07-18 20:16:43 +08:00
Lin Jen-Shin 3922b80329 Rename the methods to make it fit with current name 2017-07-18 18:04:20 +08:00
Lin Jen-Shin ffc5b29bd0 Follow feedback on the merge request 2017-07-18 17:48:48 +08:00
Lin Jen-Shin 143fc48aba Add RequestStoreWrap to cache via RequestStore
I don't like the idea of `RequestStore` at all, because it's just a
global state which shouldn't be used at all. But we have a number of
places calling `ProtectedBranch.protected?` and `ProtectedTag.protected?`
in a loop for the same user, project, and ref whenever we're checking
against if the jobs for a given pipeline is accessible for a given user.
This means we're effectively making N queries for the same thing over
and over.

To properly fix this, we need to change how we check the permission,
and that could be a huge work. To solve this quickly, adding a cache
layer for the given request would be quite simple to do.

We're already doing this in Commit#author, and this is extending that
idea and make it generalized.
2017-07-17 23:24:46 +08:00
Lin Jen-Shin 216bf78fd1 Introduce Gitlab::Cache::RequestStoreWrap
So that we cache the result of UserAccess#can_push_or_merge_to_branch?
in RequestStore, avoiding querying ProtectedBranch over and over for
the list of pipelines (i.e. in PipelineSerializer)

I don't think this is ideal because I don't like the idea of
RequestStore in general, but this is the easiest way to cache it
without changing the architecture. In the future we should cache
more explicitly rather than this kind of global store.
2017-07-04 21:56:41 +08:00
Lin Jen-Shin 23bfd8c13c Consistently check permission for creating pipelines,
updating builds and updating pipelines. We check against
being able to merge or push if the ref is protected.
2017-07-04 05:01:05 +08:00
Sam Rose 1ebd9dad8e Add confirm delete protected branch modal 2017-05-08 07:41:58 +00:00
Pawel Chojnacki 19edeba8e3 Prevent people from creating branches if they don't have persmission to push 2017-04-28 16:05:00 +02:00
James Edwards-Jones d85471ac1a Fixed UserAccess#can_create_tag? after create_access_levels rename 2017-04-04 03:50:15 +01:00
James Edwards-Jones 1e15444ae6 Cleanup & tests for UserAccess#can_create_tag? 2017-04-04 02:05:42 +01:00
James Edwards-Jones bf3cc824e4 Moved Project#protected_branch? to ProtectedBranch, similar for tags 2017-04-03 19:19:54 +01:00
James Edwards-Jones 65f3d5062f Extract ProtectedRef Concern 2017-04-03 17:19:53 +01:00
James Edwards-Jones e3fbcd0093 Protected Tags enforced over git 2017-03-31 19:37:38 +01:00
http://jneen.net/ 90d924dc39 reverse the logic and use a clearer name 2017-03-09 13:59:19 -08:00
http://jneen.net/ 145f6fd0b9 protect git access through the policy infra 2017-03-09 11:49:52 -08:00
Pawel Chojnacki eb9b964054 Allow creating protected branch when it doesn't exist
if user has either push or merge permissions

+ Change log entry for fix to creating a branch matching a wildcard fails
2017-01-13 10:53:59 -05:00
Lin Jen-Shin 48090a9188 Introduce no_user_or_blocked? and fix tests due to
checking user permission.
2016-11-16 22:07:04 +08:00
Timothy Andrew 4ddbbcd11a Improve EE compatibility with protected branch access levels.
1. Change a few incorrect `access_level` to `access_levels.first` that
   were missed in e805a64.

2. `API::Entities` can iterate over all access levels instead of just
   the first one. This makes no difference to CE, and makes it more compatible
   with EE.
2016-08-16 12:08:10 +05:30
tiagonbotelho 482d7802cc changes default_branch_protection to allow devs_can_merge protection option aswell 2016-08-04 21:15:26 +01:00
Timothy Andrew 828f6eb6e5 Enforce "No One Can Push" during git operations.
1. The crux of this change is in `UserAccess`, which looks through all
   the access levels, asking each if the user has access to push/merge
   for the current project.

2. Update the `protected_branches` factory to create access levels as
   necessary.

3. Fix and augment `user_access` and `git_access` specs.
2016-07-29 15:20:39 +05:30
Rémy Coutable 2cf7f09b1e
Revert "Revert "Merge branch '18193-developers-can-merge' into 'master' ""
This reverts commit 530f5158e2.

See !4892.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-07-18 10:16:56 +02:00
Robert Speicher 530f5158e2 Revert "Merge branch '18193-developers-can-merge' into 'master' "
This reverts commit 9ca633eb4c, reversing
changes made to fb229bbf79.
2016-07-13 13:57:30 -05:00
Timothy Andrew 60245bbe22 Refactor `Gitlab::GitAccess`
1. Don't use case statements for dispatch anymore. This leads to a lot
   of duplication, and makes the logic harder to follow.

2. Remove duplicated logic.

    - For example, the `can_push_to_branch?` exists, but we also have a
      different way of checking the same condition within `change_access_check`.

    - This kind of duplication is removed, and the `can_push_to_branch?`
      method is used in both places.

3. Move checks returning true/false to `UserAccess`.

    - All public methods in `GitAccess` now return an instance of
      `GitAccessStatus`. Previously, some methods would return
      true/false as well, which was confusing.

    - It makes sense for these kinds of checks to be at the level of a
      user, so the `UserAccess` class was repurposed for this. The prior
      `UserAccess.allowed?` classmethod is converted into an instance
      method.

    - All external uses of these checks have been migrated to use the
      `UserAccess` class

4. Move the "change_access_check" into a separate class.

    - Create the `GitAccess::ChangeAccessCheck` class to run these
      checks, which are quite substantial.

    - `ChangeAccessCheck` returns an instance of `GitAccessStatus` as
      well.

5. Break out the boolean logic in `ChangeAccessCheck` into `if/else`
   chains - this seems more readable.

6. I can understand that this might look like overkill for !4892, but I
   think this is a good opportunity to clean it up.

    - http://martinfowler.com/bliki/OpportunisticRefactoring.html
2016-07-13 13:24:56 +05:30
Jacob Vosmaer e7df3f51c9 Move method to User 2016-03-10 12:37:14 +01:00