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

website publish without metadata #1

Merged
merged 3 commits into from
Oct 31, 2023
Merged

website publish without metadata #1

merged 3 commits into from
Oct 31, 2023

Conversation

Anas12091101
Copy link
Owner

@Anas12091101 Anas12091101 commented Oct 20, 2023

What are the relevant tickets?

Fixes # 1996

Description (What does it do?)

You can add content to a course and publish it in staging without ever visiting the Metadata section. Production, however will require metadata to be set.

Screenshots (if appropriate):

Screenshot 2023-10-20 at 2 34 36 PM Screenshot 2023-10-20 at 2 35 37 PM Screenshot 2023-10-20 at 2 35 51 PM

How can this be tested?

  • Go to the studio website and login as admin
  • Create a new site with ocw-course starter
  • (Optional) Add pages to the website
  • Open the publish drawer, you can see that the publish button is enabled in the staging and disabled in production (as we have not set metadata yet)
  • Press the publish button in staging
  • After the pipeline finishes, you get the published website on the url

Additional Context

The course-v2/layouts/partials/course_banner.html file was changed in the ocw-hugo-themes repository. You can view the changes here

Copy link

@HussainTaj-arbisoft HussainTaj-arbisoft left a comment

Choose a reason for hiding this comment

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

The general approach seems good to me.

I have a few questions and suggestions. I didn't get the time to run the code myself. I'll do that tomorrow and get back to you if I find something new.

@@ -123,7 +123,7 @@ const PublishingOption: React.FC<PublishingOptionProps> = (props) => {
)}
<PublishForm
onSubmit={handlePublish}
disabled={!publishingInfo.hasUnpublishedChanges}
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")}

Choose a reason for hiding this comment

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

Would it be better to use the PublishingEnv enum from static/js/constants.ts?

Suggested change
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")}
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv===PublishingEnv.Production)}

Copy link
Owner Author

Choose a reason for hiding this comment

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

yes, seems more clean

@@ -123,7 +123,7 @@ const PublishingOption: React.FC<PublishingOptionProps> = (props) => {
)}
<PublishForm
onSubmit={handlePublish}
disabled={!publishingInfo.hasUnpublishedChanges}
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")}

Choose a reason for hiding this comment

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

This condition is rather long, maybe we could refactor it into a separate variable?

This is just a suggestion. It is up to your discretion.

const isPublishDisabled = (
  !publishingInfo.hasUnpublishedChanges
  || !website.has_site_metadata && publishingEnv==="production"
)

@@ -263,6 +257,10 @@ def get_draft_url(self, instance):
"""Get the draft url for the site"""
return instance.get_full_url(version=VERSION_DRAFT)

def get_has_site_metadata(self, instance):
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")
return True if (site_metadata and site_metadata.metadata) else False

Choose a reason for hiding this comment

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

Your code is correct. In my opinion, we can make it easier to read too.

Suggested change
return True if (site_metadata and site_metadata.metadata) else False
return bool(site_metadata and site_metadata.metadata)

Comment on lines 260 to 262
def get_has_site_metadata(self, instance):
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")
return True if (site_metadata and site_metadata.metadata) else False

Choose a reason for hiding this comment

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

I think we need to add this in WebsiteStatusSerializer.

I'm not sure if it is required in WebsiteDetailSerializer. If it is required in both serializers then I think it would be best to create a mixin, like WebsiteHasMetadataSerializer.

Comment on lines 62 to 60
// Updating website's has_site_metadata to true
store.dispatch(updateEntities({websiteDetails : (prevValue)=>{
const updatedSite = {...prevValue[site.name], has_site_metadata:true}
let newVal = prevValue;
newVal[site.name] = updatedSite;
return newVal}}))
}

Choose a reason for hiding this comment

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

Is this required?

I thought the following code was enough to fetch new data from the backend.

store.dispatch(requestAsync(websiteStatusRequest(site.name)))

Also, since this piece of code sets has_site_metadata: true for any form submission, I think saving a page will enable the button even when the metadata is not present.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, I didn't go through the working of WebsiteStatus requests in the code. Will update it soon.

Copy link

@HussainTaj-arbisoft HussainTaj-arbisoft left a comment

Choose a reason for hiding this comment

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

Functionally this is good. I do have some suggestions on refactoring some code. And it would be awesome to format this code using our configured formatters.

@@ -6,6 +6,7 @@ import { requestAsync } from "redux-query"

import SiteContentForm from "./forms/SiteContentForm"
import { useWebsite } from "../context/Website"
import { updateEntities } from 'redux-query';

Choose a reason for hiding this comment

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

Is this import being used?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No, removing it

Comment on lines 323 to 330
has_site_metadata = serializers.SerializerMethodField(read_only=True)

"""Serializer for website status fields"""

def get_has_site_metadata(self, instance):
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")
return bool(site_metadata and site_metadata[0].metadata)

Choose a reason for hiding this comment

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

We're repeating this logic twice.

Maybe we should create a Mixin called WebsiteStatusMixin. Let me know if you need help with this.

@Anas12091101 Anas12091101 force-pushed the Issue_metadata branch 3 times, most recently from 841d148 to d177b90 Compare October 25, 2023 12:28
Copy link

@HussainTaj-arbisoft HussainTaj-arbisoft left a comment

Choose a reason for hiding this comment

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

Looks good. Just a minor suggestion.

Comment on lines 236 to 237
class WebsiteHasMetadataMixin(serializers.Serializer):
has_site_metadata = serializers.SerializerMethodField(read_only=True)

Choose a reason for hiding this comment

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

It's always a good idea to add doc strings.

Suggested change
class WebsiteHasMetadataMixin(serializers.Serializer):
has_site_metadata = serializers.SerializerMethodField(read_only=True)
class WebsiteHasMetadataMixin(serializers.Serializer):
"""Adds has_site_metadata custom serializer field."""
has_site_metadata = serializers.SerializerMethodField(read_only=True)

Comment on lines 239 to 240
def get_has_site_metadata(self, instance):
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")

Choose a reason for hiding this comment

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

Suggested change
def get_has_site_metadata(self, instance):
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")
def get_has_site_metadata(self, instance):
"""Get whether or not the site has metadata."""
site_metadata = instance.websitecontent_set.filter(type="sitemetadata")

Comment on lines 324 to 325
"""Serializer for website status fields"""

Choose a reason for hiding this comment

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

Was there a reason for removing this docstring?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No, removed by mistake

@Anas12091101 Anas12091101 merged commit 5054711 into master Oct 31, 2023
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.

2 participants