From 606a1d2d31aff69ddabe7e3794f61f3e778da3e8 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Thu, 22 Aug 2019 22:08:28 +0000 Subject: Expose namespace storage statistics with GraphQL Root namespaces have storage statistics. This commit allows namespace owners to get those stats via GraphQL queries like the following one { namespace(fullPath: "a_namespace_path") { rootStorageStatistics { storageSize repositorySize lfsObjectsSize buildArtifactsSize packagesSize wikiSize } } } --- app/policies/group_policy.rb | 2 ++ app/policies/namespace/root_storage_statistics_policy.rb | 5 +++++ app/policies/namespace_policy.rb | 1 + 3 files changed, 8 insertions(+) create mode 100644 app/policies/namespace/root_storage_statistics_policy.rb (limited to 'app/policies') diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb index c686e7763bb..5d2b74b17a2 100644 --- a/app/policies/group_policy.rb +++ b/app/policies/group_policy.rb @@ -124,6 +124,8 @@ class GroupPolicy < BasePolicy rule { developer & developer_maintainer_access }.enable :create_projects rule { create_projects_disabled }.prevent :create_projects + rule { owner | admin }.enable :read_statistics + def access_level return GroupMember::NO_ACCESS if @user.nil? diff --git a/app/policies/namespace/root_storage_statistics_policy.rb b/app/policies/namespace/root_storage_statistics_policy.rb new file mode 100644 index 00000000000..63fcaf20dfe --- /dev/null +++ b/app/policies/namespace/root_storage_statistics_policy.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Namespace::RootStorageStatisticsPolicy < BasePolicy + delegate { @subject.namespace } +end diff --git a/app/policies/namespace_policy.rb b/app/policies/namespace_policy.rb index 2babcb0a2d9..937666c7e54 100644 --- a/app/policies/namespace_policy.rb +++ b/app/policies/namespace_policy.rb @@ -11,6 +11,7 @@ class NamespacePolicy < BasePolicy enable :create_projects enable :admin_namespace enable :read_namespace + enable :read_statistics end rule { personal_project & ~can_create_personal_project }.prevent :create_projects -- cgit v1.2.1