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.



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

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

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


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

def allowed?
  return true if snippet_migration?

  super
end

#can_create_tag?(ref) ⇒ Boolean

Returns:

  • (Boolean)


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

def can_create_tag?(ref)
  false
end

#can_delete_branch?(ref) ⇒ Boolean

Returns:

  • (Boolean)


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

def can_delete_branch?(ref)
  false
end

#can_do_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

def can_merge_to_branch?(ref)
  false
end

#can_push_to_branch?(ref) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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