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

🪲 Running programs throws an error if logged in #5513

Merged
merged 9 commits into from
May 10, 2024
4 changes: 2 additions & 2 deletions tests/cypress/e2e/public_programs/programs_page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("General tests for my programs page (with both custom teacher and built
const adventure = 'story'
beforeEach(() => {
loginForTeacher();
})
})

it("create adventure, run its code, and see it in my programs", () => {
createAdventure(programName);
Expand All @@ -31,7 +31,7 @@ describe("General tests for my programs page (with both custom teacher and built
// make sure to navigate to the wanted program tab.
cy.get(`[data-cy="${adventure}"]`)
.click();
// Paste example code
// Paste example code
cy.get(`[data-cy="paste-example-code-${adventure}"]`).click();
cy.get('#runit').click();
cy.wait(500);
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/tools/profile/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export function makeProfilePublic() {
goToProfilePage();
cy.get('#public_profile_button').click();
cy.get('#personal_text').type('updating profile to be public');
cy.get('#agree_terms').click();
cy.get('#agree_terms').check(); // May start out checked, in which case 'click()' would undo the check!
cy.get('#submit_public_profile').click();
}
3 changes: 1 addition & 2 deletions website/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,7 @@ def set_favourite_program(self, username, program_id, set_favourite):
# We can only set a favourite program is there is already a public profile
data = PUBLIC_PROFILES.get({"username": username})
if data:
data["favourite_program"] = program_id if set_favourite else ''
self.update_public_profile(username, data)
self.update_public_profile(username, {"favourite_program": program_id if set_favourite else ''})
return True
return False

Expand Down
7 changes: 7 additions & 0 deletions website/dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def update(self, key, updates):
self._validate_indexable_fields(updates, True)
self._validate_key(key)

updating_keys = set(updates.keys()) & set(self.key_schema.key_names)
if updating_keys:
raise RuntimeError(' '.join([
'update() may not include a key field in the \'updates\' field',
f'({updating_keys} may not be part of {updates};',
'did you accidentally pass an entire record to update()?)']))

return self.storage.update(self.table_name, key, updates)

@querylog.timed_as("db_del")
Expand Down
5 changes: 3 additions & 2 deletions website/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def store_user_program(self,
updates['public'] = 1 if set_public else 0

if program_id:
# Updates an existing program
# FIXME: This should turn into a conditional update
current_prog = self.db.program_by_id(program_id)
if not current_prog:
Expand All @@ -86,6 +87,7 @@ def store_user_program(self,

program = self.db.update_program(program_id, updates)
else:
# Creates a new program
updates['id'] = uuid.uuid4().hex
program = self.db.store_program(updates)

Expand All @@ -101,8 +103,7 @@ def store_user_program(self,
# and if it was already modified and now is so again, count should not increase.
if is_modified and not program.get('is_modified'):
self.db.increase_user_program_count(user["username"])
program['is_modified'] = is_modified
program = self.db.update_program(program['id'], program)
program = self.db.update_program(program['id'], {'is_modified': True})

querylog.log_value(program_id=program['id'],
adventure_name=adventure_name, error=error, code_lines=len(code.split('\n')))
Expand Down
Loading