Class: Gitlab::UserAccessSnippet

Inherits:
UserAccess show all
Extended by:
Cache::RequestCache, Gitlab::Utils::Override
Defined in:
lib/gitlab/user_access_snippet.rb

Instance Attribute Summary collapse

Attributes included from Cache::RequestCache

#request_cache_key_block

Attributes inherited from UserAccess

#container, #push_ability, #user

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Cache::RequestCache

extended, request_cache, request_cache_key

Methods inherited from UserAccess

#can_push_for_ref?, #can_update_branch?, #cannot_do_action?

Constructor Details

#initialize(user, snippet: nil) ⇒ UserAccessSnippet

Returns a new instance of UserAccessSnippet.


15
16
17
18
# File 'lib/gitlab/user_access_snippet.rb', line 15

def initialize(user, snippet: nil)
  super(user, container: snippet)
  @project = snippet&.project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.


60
61
62
# File 'lib/gitlab/user_access_snippet.rb', line 60

def project
  @project
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)

20
21
22
23
24
# File 'lib/gitlab/user_access_snippet.rb', line 20

def allowed?
  return true if snippet_migration?

  super
end

#can_create_tag?(ref) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/gitlab/user_access_snippet.rb', line 36

def can_create_tag?(ref)
  false
end

#can_delete_branch?(ref) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/gitlab/user_access_snippet.rb', line 40

def can_delete_branch?(ref)
  false
end

#can_do_action?(action) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/user_access_snippet.rb', line 26

def can_do_action?(action)
  return true if snippet_migration?
  return false unless can_access_git?

  permission_cache[action] =
    permission_cache.fetch(action) do
      Ability.allowed?(user, action, snippet)
    end
end

#can_merge_to_branch?(ref) ⇒ Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/gitlab/user_access_snippet.rb', line 51

def can_merge_to_branch?(ref)
  false
end

#can_push_to_branch?(ref) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
47
48
49
# File 'lib/gitlab/user_access_snippet.rb', line 44

def can_push_to_branch?(ref)
  return true if snippet_migration?
  return false unless snippet

  can_do_action?(:update_snippet)
end

#snippet_migration?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'lib/gitlab/user_access_snippet.rb', line 55

def snippet_migration?
  user&.migration_bot? && snippet
end