Repository: oppia/oppia
File: core/controllers/blog_dashboard.py (Python)

Code before:
                'validators': [
                    {
                        'id': 'has_length_at_most',
                        'max_value': constants.MAX_CHARS_IN_AUTHOR_BIO,
                    }
                ],
            },
        },
    }

    @acl_decorators.can_access_blog_dashboard
    def get(self) -> None:
        """Retrieves data for the blog dashboard."""
        assert self.user_id is not None
        author_details = blog_services.get_blog_author_details(
            self.user_id, strict=False
        )

        if author_details is not None:
            author_details_dict = author_details.to_dict()
        else:
            author_details_dict = {
                'displayed_author_name': '',
                'author_bio': '',
                'last_updated': None,
            }

        no_of_published_blog_posts = 0
        published_post_summary_dicts = []
        no_of_draft_blog_posts = 0
        draft_blog_post_summary_dicts = []
        published_post_summaries = (
            blog_services.get_blog_post_summary_models_list_by_user_id(
                self.user_id, True
            )
        )
        if published_post_summaries:
            no_of_published_blog_posts = len(published_post_summaries)
            published_post_summary_dicts = (
                _get_blog_card_summary_dicts_for_dashboard(
                    published_post_summaries
                )
            )

        draft_blog_post_summaries = (
            blog_services.get_blog_post_summary_models_list_by_user_id(
                self.user_id, False
            )
        )
        if draft_blog_post_summaries:
            no_of_draft_blog_posts = len(draft_blog_post_summaries)

Review comment (security):
Can we move this into `get_blog_author_details` instead? It doesn't make sense for this read-operation to have the responsibility of creating a backup dict, that should be part of `get_blog_author_details`'s job.

Code after:
                'validators': [
                    {
                        'id': 'has_length_at_most',
                        'max_value': constants.MAX_CHARS_IN_AUTHOR_BIO,
                    }
                ],
            },
        },
    }

    @acl_decorators.can_access_blog_dashboard
    def get(self) -> None:
        """Retrieves data for the blog dashboard."""
        assert self.user_id is not None
        author_details_dict = blog_services.get_blog_author_details(
            self.user_id, strict=False
        ).to_dict()

        no_of_published_blog_posts = 0
        published_post_summary_dicts = []
        no_of_draft_blog_posts = 0
        draft_blog_post_summary_dicts = []
        published_post_summaries = (
            blog_services.get_blog_post_summary_models_list_by_user_id(
                self.user_id, True
            )
        )
        if published_post_summaries:
            no_of_published_blog_posts = len(published_post_summaries)
            published_post_summary_dicts = (
                _get_blog_card_summary_dicts_for_dashboard(
                    published_post_summaries
                )
            )

        draft_blog_post_summaries = (
            blog_services.get_blog_post_summary_models_list_by_user_id(
                self.user_id, False
            )
        )
        if draft_blog_post_summaries:
            no_of_draft_blog_posts = len(draft_blog_post_summaries)
            draft_blog_post_summary_dicts = (
                _get_blog_card_summary_dicts_for_dashboard(
                    draft_blog_post_summaries
                )
            )
        self.values.update(
            {
                'author_details': author_details_dict,
                'no_of_published_blog_posts': no_of_published_blog_posts,