Skip to content

Commit 4b1823d

Browse files
authored
Merge pull request code-dot-org#15200 from code-dot-org/fix-gallery-project-links
Fix project links in the public gallery
2 parents 30b7045 + e981475 commit 4b1823d

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

dashboard/lib/projects_list.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def fetch_published_project_types(project_types, limit:, offset: 0)
9090
{}.tap do |projects|
9191
project_types.map do |type|
9292
projects[type] = PEGASUS_DB[:storage_apps].
93+
select_append(Sequel[:storage_apps][:id].as(:channel_id)).
9394
join(:user_storage_ids, id: :storage_id).
9495
join(users, id: :user_id).
9596
where(state: 'active', project_type: type).
@@ -104,7 +105,7 @@ def fetch_published_project_types(project_types, limit:, offset: 0)
104105

105106
def get_published_project_data(project)
106107
project_value = project[:value] ? JSON.parse(project[:value]) : {}
107-
channel_id = storage_encrypt_channel_id(project[:storage_id], project[:id])
108+
channel_id = storage_encrypt_channel_id(project[:storage_id], project[:channel_id])
108109
{
109110
channel: channel_id,
110111
name: project_value['name'],

dashboard/test/controllers/api/v1/projects/public_gallery_controller_test.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class Api::V1::Projects::PublicGalleryControllerTest < ActionController::TestCas
44
published_applab_project = nil
55
setup do
66
published_applab_project = {
7-
id: 33,
7+
storage_id: 22,
8+
channel_id: 33,
89
published_at: '2017-03-03T00:00:00.000-08:00',
910
project_type: 'applab',
1011
value: {
@@ -95,7 +96,7 @@ class Api::V1::Projects::PublicGalleryControllerTest < ActionController::TestCas
9596
assert_equal 1, categories_list.length
9697
project_row = categories_list['applab'].first
9798
assert_equal 'Charlies App', project_row['name']
98-
assert_equal 'STUB_CHANNEL_ID-1234', project_row['channel']
99+
assert_equal 'STUB_CHANNEL_ID-22-33', project_row['channel']
99100
assert_equal '/v3/files-public/charlies_thumbnail.png', project_row['thumbnailUrl']
100101
assert_equal 'applab', project_row['type']
101102
assert_equal '2017-03-03T00:00:00.000-08:00', project_row['publishedAt']
@@ -111,7 +112,7 @@ class Api::V1::Projects::PublicGalleryControllerTest < ActionController::TestCas
111112
assert_equal 1, categories_list.length
112113
project_row = categories_list['applab'].first
113114
assert_equal 'App with no thumbnail', project_row['name']
114-
assert_equal nil, project_row['thumbnailUrl']
115+
assert_nil project_row['thumbnailUrl']
115116
end
116117

117118
test 'project details are correct listing all published projects' do
@@ -128,7 +129,7 @@ class Api::V1::Projects::PublicGalleryControllerTest < ActionController::TestCas
128129

129130
project_row = categories_list['applab'].first
130131
assert_equal 'Charlies App', project_row['name']
131-
assert_equal 'STUB_CHANNEL_ID-1234', project_row['channel']
132+
assert_equal 'STUB_CHANNEL_ID-22-33', project_row['channel']
132133
assert_equal '/v3/files-public/charlies_thumbnail.png', project_row['thumbnailUrl']
133134
assert_equal 'applab', project_row['type']
134135
assert_equal '2017-03-03T00:00:00.000-08:00', project_row['publishedAt']
@@ -139,6 +140,6 @@ class Api::V1::Projects::PublicGalleryControllerTest < ActionController::TestCas
139140
private
140141

141142
def db_result(result)
142-
stub(join: stub(join: stub(where: stub(exclude: stub(order: stub(limit: stub(offset: result)))))))
143+
stub(select_append: stub(join: stub(join: stub(where: stub(exclude: stub(order: stub(limit: stub(offset: result))))))))
143144
end
144145
end

dashboard/test/controllers/api/v1/projects/section_projects_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Api::V1::Projects::SectionProjectsControllerTest < ActionController::TestC
7373
# this verifies that the hidden project was not shown.
7474
assert_equal 1, projects_list.size
7575
project_row = projects_list.first
76-
assert_equal 'STUB_CHANNEL_ID-1234', project_row['channel']
76+
assert_equal 'STUB_CHANNEL_ID-11-22', project_row['channel']
7777
assert_equal 'Bobs App', project_row['name']
7878
assert_equal @student.name, project_row['studentName']
7979
assert_equal 'applab', project_row['type']

dashboard/test/controllers/xhr_proxy_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class XhrProxyControllerTest < ActionController::TestCase
88
XHR_URI = 'https://www.wikipedia.org/foo?a=1&b=2'
99
XHR_DATA = '{"key1":"value1", "key2":2, "obj":{"x":3, "y":4}}'
1010
XHR_CONTENT_TYPE = 'application/json'
11-
CHANNEL_ID = $stub_encrypted_channel_id
11+
CHANNEL_ID = 'STUB_CHANNEL_ID-1234'
1212
BAD_CHANNEL_MSG = "XhrProxyController request with invalid channel_id"
1313

1414
test "should fetch proxied media with correct content type" do

dashboard/test/test_helper.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,8 @@ def storage_id(_)
450450
SecureRandom.hex
451451
end
452452

453-
$stub_encrypted_channel_id = 'STUB_CHANNEL_ID-1234'
454-
def storage_encrypt_channel_id(_, _)
455-
$stub_encrypted_channel_id
453+
def storage_encrypt_channel_id(storage_id, channel_id)
454+
"STUB_CHANNEL_ID-#{storage_id}-#{channel_id}"
456455
end
457456

458457
$stub_channel_owner = 33

0 commit comments

Comments
 (0)