Skip to content

Commit

Permalink
feat: request anonymized offering data explicitly when using research…
Browse files Browse the repository at this point in the history
…er UI [PT-187154175]
  • Loading branch information
pjanik committed Apr 3, 2024
1 parent 8ec4cca commit 40a1961
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rails/app/assets/javascripts/react-components.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion rails/app/controllers/api/v1/offerings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def show

authorize offering, :api_show?

anonymize_students = !current_user.has_full_access_to_student_data?(offering.clazz)
researcher_view = params[:researcher].present? && params[:researcher] != 'false'

anonymize_students = researcher_view || !current_user.has_full_access_to_student_data?(offering.clazz)

offering_api = API::V1::Offering.new(offering, request.protocol, request.host_with_port, current_user, params[:add_external_report], anonymize_students)
render :json => offering_api.to_json, :callback => params[:callback]
Expand Down
4 changes: 3 additions & 1 deletion rails/app/policies/portal/offering_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def report?
end

def external_report?
researcher_view = params[:researcher].present? && params[:researcher] != 'false'

if class_teacher_or_admin?
true
elsif params[:researcher] && class_researcher?
elsif researcher_view && class_researcher?
true
else
class_student? &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class Assignments extends React.Component {

jQuery.ajax({
type: 'GET',
url: appendOfferingApiQueryParams(offering.apiUrl),
url: appendOfferingApiQueryParams(offering.apiUrl, researcher ? { researcher: true } : {}),
success: data => {
const newData = offeringDetailsMapping(data, researcher)
const { offeringDetails } = this.state
Expand Down
23 changes: 15 additions & 8 deletions react-components/src/library/url-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ const ADD_EXTERNAL_REPORT = 'add_external_report'
// This function will take search params from the current URL, parse them, check if there are any params
// that are supported by Offering API, and it will append these query params to Offering API URL provided as an
// argument. It ensures that apiUrl won't get broken, even if if already has some search params included.
export const appendOfferingApiQueryParams = apiUrl => {
export const appendOfferingApiQueryParams = (apiUrl, explicitParams = {}) => {
const currentUrl = new URL(window.location)
const FAKE_BASE_URL = 'http://fake.base.url.com'
// Note that URL module only works with absolute URLs. FAKE_BASE_URL will be ignored if apiUrl is already absolute,
// or used otherwise and finally stripped out (return statement).
const apiUrlParsed = new URL(apiUrl, FAKE_BASE_URL)

// Automatically append ADD_EXTERNAL_REPORT if present in the current URL
if (currentUrl.searchParams.has(ADD_EXTERNAL_REPORT)) {
// Note that URL module only works with absolute URLs. FAKE_BASE_URL will be ignored if apiUrl is already absolute,
// or used otherwise and finally stripped out (return statement).
const FAKE_BASE_URL = 'http://fake.base.url.com'
const apiUrlParsed = new URL(apiUrl, FAKE_BASE_URL)
apiUrlParsed.searchParams.set(ADD_EXTERNAL_REPORT, currentUrl.searchParams.get(ADD_EXTERNAL_REPORT))
return apiUrlParsed.toString().replace(FAKE_BASE_URL, '')
} else {
return apiUrl
}

// Manually append any explicitParams provided as an argument
Object.keys(explicitParams).forEach(key => {
apiUrlParsed.searchParams.set(key, explicitParams[key])
})

// Return the modified URL, removing the FAKE_BASE_URL if it was added
return apiUrlParsed.toString().replace(FAKE_BASE_URL, '')
}

0 comments on commit 40a1961

Please sign in to comment.