Class: Feature::Gitaly

Inherits:
Object
  • Object
show all
Defined in:
lib/feature/gitaly.rb

Defined Under Namespace

Classes: ActorWrapper

Constant Summary collapse

PREFIX =
"gitaly_"

Class Method Summary collapse

Class Method Details

.enabled_for_any?(feature_flag, *actors) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/feature/gitaly.rb', line 20

def enabled_for_any?(feature_flag, *actors)
  return false unless Feature::FlipperFeature.table_exists?

  actors = actors.compact
  return Feature.enabled?(feature_flag, type: :undefined, default_enabled_if_undefined: false) if actors.empty?

  actors.any? do |actor|
    Feature.enabled?(feature_flag, actor, type: :undefined, default_enabled_if_undefined: false)
  end
rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad
  false
end

.group_actor(container) ⇒ Object



60
61
62
63
# File 'lib/feature/gitaly.rb', line 60

def group_actor(container)
  return actor_wrapper(::Group, container.namespace_id) if container.is_a?(::Project)
  return actor_wrapper(::Group, container.project.namespace_id) if container.is_a?(DesignManagement::Repository)
end

.project_actor(container) ⇒ Object



55
56
57
58
# File 'lib/feature/gitaly.rb', line 55

def project_actor(container)
  return actor_wrapper(::Project, container.id) if container.is_a?(::Project)
  return actor_wrapper(::Project, container.project.id) if container.is_a?(DesignManagement::Repository)
end

.server_feature_flags(repository: nil, user: nil, project: nil, group: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/feature/gitaly.rb', line 33

def server_feature_flags(repository: nil, user: nil, project: nil, group: nil)
  # We need to check that both the DB connection and table exists
  return {} unless FlipperFeature.database.cached_table_exists?

  # The order of actors here is significant. Percentage-based actor selection may not work as expected if this
  # order changes. We want repository actor to take highest precedence.
  actors = [repository, user, project, group].compact

  Feature.persisted_names
    .select { |f| f.start_with?(PREFIX) }
    .to_h do |f|
      ["gitaly-feature-#{f.delete_prefix(PREFIX).tr('_', '-')}", enabled_for_any?(f, *actors).to_s]
    end
end

.user_actor(user = nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/feature/gitaly.rb', line 48

def user_actor(user = nil)
  return ::Feature::Gitaly::ActorWrapper.new(::User, user.id) if user.is_a?(::User)

  user_id = Gitlab::ApplicationContext.current_context_attribute(:user_id)
  ::Feature::Gitaly::ActorWrapper.new(::User, user_id) if user_id
end