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

Clean up workshop dashboard: make proper js entry point, remove globa… #21689

Merged
merged 2 commits into from
Apr 5, 2018

Conversation

aoby
Copy link
Contributor

@aoby aoby commented Apr 5, 2018

…ls, add shared constants, add redux.

I also cleaned up the client-side Permission class slightly and moved it into WorkshopDashboard since that's the only place it's used.

This has been a long tech debt item that I chose now as a prerequisite to filtering which courses facilitators have access to when creating workshops (#21690). That feature, which requires passing new data (the allowed courses) from server to client, is much simpler with a cleaner entry point and redux.

It might be easier to review with whitespace ignored: https://github.com/code-dot-org/code-dot-org/pull/21689/files?w=1

The Ruby workshop constants are unchanged, just moved into two new modules (Pd::SharedWorkshopConstants which is shared with JS, and Pd::WorkshopConstants for Ruby only, which includes the former).

componentWillMount() {
if (this.props.showSurveyUrl) {
this.permission = new Permission();
constructor(props) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice cleanup of to-be-deprecated lifecycle method.

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

That's a pretty big commit, but it all looks solid. Providing permissions through redux makes a lot of sense, as long as we're not trusting anything on the client 😁.

if (this.props.showSurveyUrl) {
this.permission = new Permission();
constructor(props) {
super(props);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for? Does the base class have any constuctor logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is required because the base React.Component expects props in the constructor. This is a common React pattern. See https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class

}
};
};

it("Detects workshop admin", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like all of this is DRY-able.

permission_types = ['WorkshopAdmin', 'Facilitator', 'Organizer', 'ProgramManager', 'Partner'];

permission_types.each ((type) => {
const permission = new Permission([type])
expect(permission.has(type)).to.be.true;
permission_types - type.each((other_type) => {
expect(permission.hash(other_type)).to.be.false;
})

Something along those lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but I didn't change this test, just got it to work with the new format. I'd like to clean it up in a future PR since this one is already large.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here you go: #21702

@@ -0,0 +1,65 @@
module Pd
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this generated from the other worshop_constants file? If so, should this be checked in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is the source of the shared constants. It's included in Pd::WorkshopConstants, which also contains non-shared Ruby-only constants, and it generates a javascript /apps/src/generated/pd/sharedWorkshopConstants.js file which is not checked in. In fact everything under apps/src/generated is gitignored.

@aoby
Copy link
Contributor Author

aoby commented Apr 5, 2018

@islemaster yeah sorry this got a bit larger than I initially intended. I could have split it up into a few smaller PRs. Thanks for diving in!

The permissions were earlier provided globally on the window object so they still could have been edited in-client. That hasn't changed. We do have protections in the API calls, so all a nefarious user could do is show extra UI options but not save changes. Also only workshop admins, organizers, facilitators, etc can even access the workshop dashboard, enforced on the server.

@aoby aoby merged commit 4d4e2e3 into staging Apr 5, 2018
@aoby aoby deleted the pd-workshop-dashboard-clean-entry branch April 5, 2018 21:03
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