Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow course sharing name to be changed #9860

Merged

Conversation

Michael-Holmes-SDE
Copy link
Contributor

@Michael-Holmes-SDE Michael-Holmes-SDE commented May 15, 2024

This pull request allows the 'Course Sharing Name' to be changed, as long as the course has no publicly shared questions and no questions have been imported from the current course

implements part of #7895

Copy link
Contributor

github-actions bot commented May 15, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Michael-Holmes-SDE
Copy link
Contributor Author

I have reviewed and hereby sign the CLA

@Michael-Holmes-SDE
Copy link
Contributor Author

recheck

@nwalters512 nwalters512 changed the title Course sharing name change Allow course sharing name to be changed May 15, 2024
Copy link
Contributor

@nwalters512 nwalters512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One UI comment; other than that, you'll need to run our formatter on this code. You can either rely on the extensions/settings in the .vscode directory if you're using VS Code, or manually run make format-js if you're not.

Comment on lines 93 to 95
<p><strong>Once you choose your course's sharing name, you may not be able to change it</strong>,
because doing so would break the assessments of other courses that have imported your questions.
<strong>If you have not yet shared any questions publicly or with other courses, you may edit your course's sharing name.</strong>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to figure out whether or not renaming is allowed at the instant the page is loaded and update the UI to say concretely "you can/cannot rename this" and disable buttons/etc. appropriately.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Michael-Holmes-SDE we talked about this in our developer meeting and decided that the easiest thing to do is this: The 'Choose sharing name' button on the page should always be enabled.

If you click on it and you are allowed to change it, the dialog you see should say that you will be allowed to edit it until you share questions.

If you click on it and you are not allowed to change it, the dialog should say that you cannot change the sharing name, because you already have shared questions--and then the dialog should not have the 'choose sharing name' button on it, just the close button to close the dialog.

@SethPoulsen
Copy link
Collaborator

Thanks for your hard work @Michael-Holmes-SDE this is a great start!

As Nathan said, you'll need to get the code formatters working, and you should have the button enabled/disabled based on whether they are allowed to edit.

The other thing you'll need to do (I can't remember if I told you this before or not, sorry) is to add some automated tests verifying that the functionality works.

The automated tests for this page are in apps/prairielearn/src/tests/questionSharing.test.ts.

You'll want to have one test where you can successfully change the name if nothing has been shared yet, probably around here:

step('Fail if trying to set an invalid sharing name', async () => {
let res = await setSharingName(sharingCourse.id, 'invalid@sharingname');
assert(res.status === 400);
res = await setSharingName(sharingCourse.id, 'invalid / sharingname');
assert(res.status === 400);
res = await setSharingName(sharingCourse.id, '');
assert(res.status === 400);
});
step('Set consuming course sharing name', async () => {
await setSharingName(consumingCourse.id, CONSUMING_COURSE_SHARING_NAME);
const sharingPage = await fetchCheerio(sharingPageUrl(consumingCourse.id));
assert(sharingPage.ok);
assert.include(
sharingPage.$('[data-testid="sharing-name"]').text(),
CONSUMING_COURSE_SHARING_NAME,
);
});

and they you'll want another test where it fails to change the name if they have already shared something, probably after this code:

step(`Add question "${SHARING_QUESTION_QID}" to sharing set`, async () => {
const result = await sqldb.queryOneRowAsync(sql.get_question_id, {
course_id: sharingCourse.id,
qid: SHARING_QUESTION_QID,
});
const questionSettingsUrl = `${baseUrl}/course_instance/${sharingCourse.id}/instructor/question/${result.rows[0].id}/settings`;
const resGet = await fetchCheerio(questionSettingsUrl);
assert(resGet.ok);
const token = resGet.$('#test_csrf_token').text();
const resPost = await fetch(questionSettingsUrl, {
method: 'POST',
body: new URLSearchParams({
__action: 'sharing_set_add',
__csrf_token: token,
unsafe_sharing_set_id: '1',
}),
});
assert(resPost.ok);
const settingsPageResponse = await fetchCheerio(questionSettingsUrl);
assert.include(
settingsPageResponse.$('[data-testid="shared-with"]').text(),
SHARING_SET_NAME,
);
});
});

see the docs about running tests here: https://prairielearn.readthedocs.io/en/latest/installingLocal/#running-the-test-suite

You only need to worry about running this one test file (yarn mocha src/tests/questionSharing.test.ts), you don't need to worry about running the whole test suite locally

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 98.90110% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 66.97%. Comparing base (37f5638) to head (bc3bbd3).
Report is 2 commits behind head on master.

Files Patch % Lines
...eAdminSharing/instructorCourseAdminSharing.html.ts 98.38% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9860      +/-   ##
==========================================
+ Coverage   66.78%   66.97%   +0.19%     
==========================================
  Files         454      456       +2     
  Lines       71046    71307     +261     
  Branches     5679     5714      +35     
==========================================
+ Hits        47446    47760     +314     
+ Misses      23175    23120      -55     
- Partials      425      427       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use some more types here, and I'd rather use our Modal component instead of handcrafting one, but this isn't directly related to this PR. I'll open a followup to fix these things.

<input type="hidden" name="__action" value="choose_sharing_name">
<input type="hidden" name="__csrf_token" value="${resLocals.__csrf_token}">
<div class=form-group>
<input class="form-control form-control-sm" type="text" name="course_sharing_name" required/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This input lacks an accessible label. I know this is not a change in this PR, but I'd very much appreciate adding one. IMO we also don't need to use form-control-sm here.

I also don't think this should go in the footer, or be right-aligned. Let's move this input under the "Enter the sharing name you would like..." text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a label and moved the input:

  • Screenshot 2024-05-23 164337

@SethPoulsen
Copy link
Collaborator

@nwalters512 is there an easy way to auto-approve the CI build for all PRs from @Michael-Holmes-SDE? I don't want to have to keep hitting 'approve' over and over again.

@nwalters512
Copy link
Contributor

@SethPoulsen once he lands any PR, including this one, all future CI runs will happen automatically.

@nwalters512 nwalters512 added this pull request to the merge queue May 24, 2024
Merged via the queue into PrairieLearn:master with commit a492493 May 24, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants