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

Fix part of #19435: Migrate the Subtopic Viewer Page to Angular #20295

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

Lawful2002
Copy link
Contributor

@Lawful2002 Lawful2002 commented May 11, 2024

Overview

  1. This PR fixes part of Migration of Individual Pages from Webpack/AngularJS to Lazy-Loaded Angular Modules #19435.
  2. This PR does the following: Migrates the subtopic viewer page to Angular.

Essential Checklist

Please follow the instructions for making a code change.

  • I have linked the issue that this PR fixes in the "Development" section of the sidebar.
  • I have checked the "Files Changed" tab and confirmed that the changes are what I want to make.
  • I have written tests for my code.
  • The PR title starts with "Fix #bugnum: " or "Fix part of #bugnum: ...", followed by a short, clear summary of the changes.
  • I have assigned the correct reviewers to this PR (or will leave a comment with the phrase "@{{reviewer_username}} PTAL" if I can't assign them directly).

Proof that changes are correct

The server is running and we are able to access the Subtopic Viewer page without any console errors.

Logged In:

image

Logged out:

image

Video:
Screencast from 17-05-24 12:14:21 AM IST.webm

PR Pointers

Copy link

oppiabot bot commented May 11, 2024

Hi @Lawful2002, can you complete the following:

  1. The body of this PR is missing the required description, please update the body with a description of what this PR does.
    Thanks!

Copy link

oppiabot bot commented May 11, 2024

Hi @Lawful2002 please assign the required reviewer(s) for this PR. Thanks!

@Lawful2002
Copy link
Contributor Author

Lawful2002 commented May 11, 2024

I also tried this:
`class SubtopicViewerPageAccessValidator(
base.BaseHandler[Dict[str, str], Dict[str, str]]
):
""" Validates access to the Subtopic Viewer Page """

GET_HANDLER_ERROR_RETURN_TYPE = feconf.HANDLER_TYPE_JSON
URL_PATH_ARGS_SCHEMAS = {
    'classroom_url_fragment': constants.SCHEMA_FOR_CLASSROOM_URL_FRAGMENTS,
    'topic_url_fragment': constants.SCHEMA_FOR_TOPIC_URL_FRAGMENTS,
    'subtopic_url_fragment': {
        'schema': {
            'type': 'basestring',
            'validators': [{
                'id': 'is_regex_matched',
                'regex_pattern': constants.VALID_URL_FRAGMENT_REGEX
            }, {
                'id': 'has_length_at_most',
                'max_value': constants.MAX_CHARS_IN_SUBTOPIC_URL_FRAGMENT
            }]
        }
    }
}
HANDLER_ARGS_SCHEMAS: Dict[str, Dict[str, str]] = {'GET': {
    'classroom_url_fragment': constants.SCHEMA_FOR_CLASSROOM_URL_FRAGMENTS,
    'topic_url_fragment': constants.SCHEMA_FOR_TOPIC_URL_FRAGMENTS,
    'subtopic_url_fragment': {
        'schema': {
            'type': 'basestring',
            'validators': [{
                'id': 'is_regex_matched',
                'regex_pattern': constants.VALID_URL_FRAGMENT_REGEX
            }, {
                'id': 'has_length_at_most',
                'max_value': constants.MAX_CHARS_IN_SUBTOPIC_URL_FRAGMENT
            }]
        }
    }
}}

@acl_decorators.open_access
def get(self, classroom_url_fragment: str, topic_url_fragment: str, subtopic_url_fragment: str) -> None:
    """ Handles GET requests """
    topic = topic_fetchers.get_topic_by_url_fragment(topic_url_fragment)
    if not topic:
        raise self.NotFoundException
    
    user_actions_info = user_services.get_user_actions_info(self.user_id)
    topic_rights = topic_fetchers.get_topic_rights(topic.id)

    if ((topic_rights is None or not topic_rights.topic_is_published) and
        role_services.ACTION_VISIT_ANY_TOPIC_EDITOR_PAGE not in user_actions_info.actions):
        raise self.NotFoundException
    
    subtopic_id = None
    for subtopic in topic.subtopics:
        if subtopic.url_fragment == subtopic_url_fragment:
            subtopic_id = subtopic.id

    if not subtopic_id:
        raise self.NotFoundException
    
    verified_classroom_url_fragment = (
        classroom_config_services.get_classroom_url_fragment_for_topic_id(
            topic.id))
    if classroom_url_fragment != verified_classroom_url_fragment:
        raise self.NotFoundException
    
    subtopic_page = subtopic_page_services.get_subtopic_page_by_id(
        topic.id, subtopic_id, strict=False)
    if subtopic_page is None:
        raise self.NotFoundException`

Didn't help

Copy link

oppiabot bot commented May 12, 2024

Hi @Lawful2002. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

@acl_decorators.can_access_subtopic_viewer_page
def get(self, *args: str) -> None:
""" Handles GET requests """
pass
Copy link
Member

@seanlip seanlip May 12, 2024

Choose a reason for hiding this comment

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

this isn't calling self.render_json() like other GET JSON handlers do; could that be the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually in the SubtopicViewer, there is a data handler calling a render_json

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't understand. All GET JSON handlers end with self.render_json({something}) -- why doesn't this one do so?

@Lawful2002 Lawful2002 changed the title Subtopic viewer page migration Fix part of #19435: Migrate the Subtopic Viewer Page to Angular May 16, 2024
@Lawful2002 Lawful2002 marked this pull request as ready for review May 18, 2024 14:26
@Lawful2002 Lawful2002 requested review from a team as code owners May 18, 2024 14:26
@Nik-09
Copy link
Member

Nik-09 commented May 25, 2024

Sorry @Lawful2002 for the delay. I will take a look tomorrow morning. Thank you

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

4 participants