Skip to content

Commit

Permalink
Stats add new stats visibility column to user groups (#4210)
Browse files Browse the repository at this point in the history
* add stats_visibility enum and backfill rake task for user_groups

* remove detected trialing whitespace for usergroups backfill rake task

* Update 20230613165746_add_stats_visibility_to_user_groups.rb

* adding comments on stats visibility levels

* update wording of comment on stats_visbility

* update user group enum to take care of the case where we want to show aggregate stats publicly but only members can view individual stats (vs the case where only admins can view individual stats)

* update user_group.rb stats_visibilty docs without trailing whitespace

* update comments on stats visibilty levels
  • Loading branch information
yuenmichelle1 authored Jun 20, 2023
1 parent d36cdd2 commit 82762e7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
20 changes: 20 additions & 0 deletions app/models/user_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ class UserGroup < ApplicationRecord
has_many :collections, through: :owned_resources, source: :resource,
source_type: "Collection"

##
# Stats_Visibility Levels (Used for ERAS stats service)
# private_agg_only (default): Only members of a user group can view aggregate stats. Individual stats only viewable by only admins of the user group
#
# private_show_agg_and_ind: Only members of a user group can view aggregate stats. Individual stats is viewable by BOTH members and admins of the user group.
#
# public_agg_only: Anyone can view aggregate stats of the user group. Only admins of the user group can view individual stats.
#
# public_agg_show_ind_if_member: Anyone can view aggregate stats of the user group. Members and admins of the user group can view individual stats.
#
# public_show_all: Anyone can view aggregate stats of the user group and can view individual stats of the user group.
##
enum stats_visibility: {
private_agg_only: 0,
private_show_agg_and_ind: 1,
public_agg_only: 2,
public_agg_show_ind_if_member: 3,
public_show_all: 4
}

validates :display_name, presence: true
validates :name, presence: true,
uniqueness: { case_sensitive: false },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AddStatsVisibilityToUserGroups < ActiveRecord::Migration[6.1]
def change
add_column :user_groups, :stats_visibility, :integer
# defaulting to private_agg_only stats_visibility view (where members can view aggregate stats but only admins can view detailed stats)
change_column_default :user_groups, :stats_visibility, from: nil, to: 0
end
end
13 changes: 4 additions & 9 deletions db/structure.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 11.15 (Debian 11.15-1.pgdg90+1)
-- Dumped by pg_dump version 11.15

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down Expand Up @@ -1671,7 +1664,8 @@ CREATE TABLE public.user_groups (
display_name character varying,
private boolean DEFAULT true NOT NULL,
lock_version integer DEFAULT 0,
join_token character varying
join_token character varying,
stats_visibility integer DEFAULT 0
);


Expand Down Expand Up @@ -4581,6 +4575,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20211007125705'),
('20211124175756'),
('20211201164326'),
('20221018032140');
('20221018032140'),
('20230613165746');


11 changes: 11 additions & 0 deletions lib/tasks/user_groups.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

namespace :user_groups do
desc 'Backfill stats_visibility column default in batches'
task backfill_stats_visibility_column_default: :environment do
UserGroup.where(stats_visibility: nil).select(:id).find_in_batches do |user_group|
user_group_ids_to_update = user_group.map(&:id)
UserGroup.where(id: user_group_ids_to_update).update_all(stats_visibility: 0)
end
end
end

0 comments on commit 82762e7

Please sign in to comment.