Skip to content

Commit fcfeada

Browse files
committed
Allow hiding user profile avatars
1 parent b134cac commit fcfeada

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

lib/polish_open_source_rank/contexts/publication/infrastructure/sqlite/sqlite_profile_read_model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def organization_repository_profile(platform, full_name, period_start:)
116116
def fetch_user_profile(platform, login, period_start)
117117
database.fetch_all(<<~SQL, [period_start, platform, login]).first
118118
SELECT users.platform, users.github_id AS source_id, users.github_id, users.login, users.name, users.location_raw, users.city,
119-
users.country, users.email, users.homepage, users.html_url, users.avatar_url,
119+
users.country, users.email, users.homepage, users.html_url,
120+
CASE users.avatar_hidden WHEN 1 THEN NULL ELSE users.avatar_url END AS avatar_url,
120121
stats.period_start, stats.public_repo_count, stats.total_stars, stats.monthly_stars_delta,
121122
stats.merged_pull_requests_count
122123
FROM users

lib/polish_open_source_rank/infrastructure/platform_schema_migration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def ensure_current_columns
160160
if table_columns('user_monthly_stats').include?('public_activity_count')
161161
rebuild_user_monthly_stats_without_public_activity_count
162162
end
163+
add_column_unless_exists('users', 'avatar_hidden INTEGER NOT NULL DEFAULT 0')
163164
add_column_unless_exists('user_monthly_stats', 'merged_pull_requests_count INTEGER NOT NULL DEFAULT 0')
164165
add_column_unless_exists('organization_monthly_stats', 'merged_pull_requests_count INTEGER NOT NULL DEFAULT 0')
165166
add_column_unless_exists('organization_monthly_stats', 'members_count INTEGER NOT NULL DEFAULT 0')

lib/polish_open_source_rank/infrastructure/sqlite_schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS users (
6767
homepage TEXT,
6868
html_url TEXT NOT NULL,
6969
avatar_url TEXT,
70+
avatar_hidden INTEGER NOT NULL DEFAULT 0,
7071
updated_at TEXT NOT NULL,
7172
PRIMARY KEY(platform, github_id),
7273
UNIQUE(platform, login)

spec/polish_open_source_rank/contexts/publication/infrastructure/sqlite/sqlite_profile_read_model_spec.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
expect(read_model.repository_profile('github', 'alice/missing', period_start: period)).to be_nil
113113
end
114114

115+
it 'hides user avatars flagged in the database' do
116+
seed_user_record(id: 1, login: 'alice', avatar_url: 'https://avatars.example/alice.png', avatar_hidden: true)
117+
118+
profile = read_model.user_profile('github', 'alice', period_start: nil)
119+
120+
expect(profile).to include(login: 'alice', avatar_url: nil)
121+
end
122+
115123
it 'lists every public user identity for sitemap rendering' do
116124
seed_user_record(id: 1, login: 'alice')
117125
seed_user_record(id: 2, login: 'bob')
@@ -184,14 +192,24 @@ def seed_user(id:, login:, total_stars:, period_start: period, city: 'Kraków',
184192
'2026-05-01T00:10:00Z'])
185193
end
186194

187-
def seed_user_record(id:, login:, city: nil, country: nil)
195+
def seed_user_record(id:, login:, city: nil, country: nil, avatar_url: nil, avatar_hidden: false)
188196
database.execute(
189197
<<~SQL.strip,
190198
INSERT OR IGNORE INTO users(
191-
platform, github_id, login, city, country, html_url, updated_at
192-
) VALUES (?, ?, ?, ?, ?, ?, ?)
199+
platform, github_id, login, city, country, html_url, avatar_url, avatar_hidden, updated_at
200+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
193201
SQL
194-
['github', id, login, city, country, "https://github.com/#{login}", '2026-05-01T00:01:00Z']
202+
[
203+
'github',
204+
id,
205+
login,
206+
city,
207+
country,
208+
"https://github.com/#{login}",
209+
avatar_url,
210+
avatar_hidden ? 1 : 0,
211+
'2026-05-01T00:01:00Z'
212+
]
195213
)
196214
end
197215

spec/polish_open_source_rank/infrastructure/platform_schema_migration_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
expect(database.fetch_value(package_table_sql('package_crawl_runs'))).to eq(1)
1515
expect(database.fetch_value(package_table_sql('registry_package_snapshots'))).to eq(1)
1616
expect(database.fetch_value(package_table_sql('public_snapshot_publications'))).to eq(1)
17-
expect(database.table_info('users').map { |column| column.fetch('name') }).to include('platform')
17+
expect(database.table_info('users').map { |column| column.fetch('name') }).to include('platform', 'avatar_hidden')
1818
expect(database.table_info('user_monthly_stats').map { |column| column.fetch('name') })
1919
.to include('merged_pull_requests_count')
2020
expect(database.table_info('organization_monthly_stats').map { |column| column.fetch('name') })
@@ -119,6 +119,7 @@
119119

120120
expect(database.table_info('user_monthly_stats').map { |column| column.fetch('name') })
121121
.to include('merged_pull_requests_count')
122+
expect(database.table_info('users').map { |column| column.fetch('name') }).to include('avatar_hidden')
122123
expect(database.table_info('organization_monthly_stats').map { |column| column.fetch('name') })
123124
.to include('merged_pull_requests_count', 'members_count')
124125
end

0 commit comments

Comments
 (0)