diff options
Diffstat (limited to 'app/graphql/resolvers/clusters')
-rw-r--r-- | app/graphql/resolvers/clusters/agent_activity_events_resolver.rb | 25 | ||||
-rw-r--r-- | app/graphql/resolvers/clusters/agents_resolver.rb | 5 |
2 files changed, 29 insertions, 1 deletions
diff --git a/app/graphql/resolvers/clusters/agent_activity_events_resolver.rb b/app/graphql/resolvers/clusters/agent_activity_events_resolver.rb new file mode 100644 index 00000000000..b6fec3d3772 --- /dev/null +++ b/app/graphql/resolvers/clusters/agent_activity_events_resolver.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Resolvers + module Clusters + class AgentActivityEventsResolver < BaseResolver + type Types::Clusters::AgentActivityEventType, null: true + + alias_method :agent, :object + + delegate :project, to: :agent + + def resolve(**args) + return ::Clusters::Agents::ActivityEvent.none unless can_view_activity_events? + + agent.activity_events + end + + private + + def can_view_activity_events? + current_user.can?(:admin_cluster, project) + end + end + end +end diff --git a/app/graphql/resolvers/clusters/agents_resolver.rb b/app/graphql/resolvers/clusters/agents_resolver.rb index 9b8cea52e3b..5ad66ed7cdd 100644 --- a/app/graphql/resolvers/clusters/agents_resolver.rb +++ b/app/graphql/resolvers/clusters/agents_resolver.rb @@ -28,7 +28,10 @@ module Resolvers private def preloads - { tokens: :last_used_agent_tokens } + { + activity_events: { activity_events: [:user, agent_token: :agent] }, + tokens: :last_used_agent_tokens + } end end end |