Add DataDoc show page - #48084
Conversation
| <div style={styles.container}> | ||
| <div style={{marginBottom: 5}}>Markdown:</div> | ||
| <MarkdownEnabledTextarea | ||
| name={this.props.name} |
There was a problem hiding this comment.
This attribute gets passed to the textarea field, which triggers the HTML5 form to send its contents in the post request
| <a href="https://creativecommons.org/"> | ||
| <img src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" /> | ||
| <img | ||
| src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" |
There was a problem hiding this comment.
Since we're deprecating this URL, this asset will need to be moved, right? If so, I'll create a ticket for it
There was a problem hiding this comment.
Great –– tracked here https://codedotorg.atlassian.net/browse/PLAT-1956, and mentioned in follow-up work
davidsbailey
left a comment
There was a problem hiding this comment.
awesome progress! I love the sizing of these PRs 👍
| 'courses/edit': './src/sites/studio/pages/courses/edit.js', | ||
| 'courses/new': './src/sites/studio/pages/courses/new.js', | ||
| 'data_docs/new': './src/sites/studio/pages/data_docs/new.js', | ||
| 'data_docs/show': './src/sites/studio/pages/data_docs/show.js', // TODO [meg]: move to codeStudioEntries once launched |
There was a problem hiding this comment.
I am curious, why not put it there now?
There was a problem hiding this comment.
Sounds good –– will move this
| <a href="https://creativecommons.org/"> | ||
| <img src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" /> | ||
| <img | ||
| src="https://curriculum.code.org/static/img/creativeCommons-by-nc-sa.png" |
| const {dataDocName, dataDocContent} = props; | ||
|
|
||
| return ( | ||
| <> |
| @@ -1,5 +1,5 @@ | |||
| class DataDocsController < ApplicationController | |||
| before_action :require_levelbuilder_mode_or_test_env | |||
| before_action :require_levelbuilder_mode_or_test_env # TODO [meg]: add except: [:show] to launch | |||
There was a problem hiding this comment.
waiting is fine, but also this seems safe to do now -- as long as we are not linking to this page yet, the risk of a legit user ending up on this page and then becoming confused seems very low.
There was a problem hiding this comment.
Great, sounds good –– will change permissions for the show page!
| @@ -0,0 +1,2 @@ | |||
| %script{src: webpack_asset_path('js/data_docs/show.js'), data: {dataDocName: @data_doc_name.to_json, dataDocContent: @data_doc_content.to_json}} | |||
There was a problem hiding this comment.
I see that this use of to_json works today, but is a little concerning because technically only things wrapped in [] and {} are valid json, and we have run into problems like this before when we try to upgrade. my recommendation would be to wrap these two fields in a single object like data: {dataDocs: {...}.to_json}. you could also just pass them as plain strings without to_json or getScriptData.
There was a problem hiding this comment.
Oo, good to know! I ran into an error without the to_json but didn't investigate further ... will look into changing this
| sign_in @levelbuilder | ||
| new_key = "doc_key" | ||
| get :create, params: {key: new_key} | ||
| assert_match %r{/data_docs/#{new_key}$}, @response.headers['Location'] |
There was a problem hiding this comment.
great test! one nit: rails provides a... railsier way to do this assertion:
that's what I'd recommend since it seems less fragile. if that seems too abstract, this could be a possible compromise:
There was a problem hiding this comment.
Oh, that's cool! Will do that 👍
| test_user_gets_response_for :create, params: -> {@test_params}, user: :levelbuilder, response: :success | ||
|
|
||
| # TODO [meg] : all should be able to see `show` page, once launched | ||
| # for now, only levelbuilder can see it |
There was a problem hiding this comment.
again, this strategy is perfectly valid, but seems like unnecessary work to take these extra steps to protect these pages
There was a problem hiding this comment.
Sounds good –– will move these
|
|
||
| # GET /data_docs/:key | ||
| def show | ||
| @data_doc = DataDoc.find_by(key: params[:key]) |
There was a problem hiding this comment.
I am curious, do you get this for free due to the combination of load_and_authorize_resource her and param: :key in routes.rb ? I would suggest removing this statement and seeing if everything still works (CanCan should define @data_doc for you). if not... no need to investigate too much, sometimes CanCan doesn't quite work as expected when the param is not id.
There was a problem hiding this comment.
Just tried it: @data_doc isn't defined ... also, in the create method, I originally tried
if @data_doc.save
redirect_to @data_doc
and got the same problem (it tried to use the id in the URL, which I was surprised by given the param: :key in routes)
This work is part of https://codedotorg.atlassian.net/browse/PLAT-1279 –– Curriculum Writers can add new Data Docs.
This PR allows you to see the data doc after you've created it. To see functionality, go to http://localhost-studio.code.org:3000/data_docs/new. It should make you add Levelbuilder permissions to your local account before you can view the page, and after putting in info, the site redirects to the newly-created data doc.
See functionality: https://watch.screencastify.com/v/kVoYeC6J8jnxu5iugfNK
Links
Spec
Engineering Plan
Testing story
I added unit tests for these. In a separate PR, will add a UI test, ensuring a user can create and then see the data doc.
Deployment strategy
Follow-up work
Add UI test, and move asset out of curriculum builder (tracked here https://codedotorg.atlassian.net/browse/PLAT-1956)
Add UI test
Privacy
Security
Caching
PR Checklist: