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: Learner group editor page migration #19761

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix part of #19435: Migrate learner group editor page
  • Loading branch information
AFZL210 committed Feb 15, 2024
commit e693149862d03cb982ff1df44687ad5bf378aeea
18 changes: 18 additions & 0 deletions assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7214,6 +7214,24 @@ export default {
}
]
},
"LEARNER_GROUP_EDITOR": {
"ROUTE": "edit-learner-group/:learner_group_id",
DubeySandeep marked this conversation as resolved.
Show resolved Hide resolved
"TITLE": "Edit Learner Group | Oppia",
"META": [
{
"PROPERTY_TYPE": "itemprop",
"PROPERTY_VALUE": "description",
// eslint-disable-next-line max-len
"CONTENT": "With Oppia, you can access free lessons on math, physics, statistics, chemistry, music, history and more from anywhere in the world. Oppia is a nonprofit with the mission of providing high-quality education to those who lack access to it."
},
{
"PROPERTY_TYPE": "itemprop",
"PROPERTY_VALUE": "og:description",
// eslint-disable-next-line max-len
"CONTENT": "With Oppia, you can access free lessons on math, physics, statistics, chemistry, music, history and more from anywhere in the world. Oppia is a nonprofit with the mission of providing high-quality education to those who lack access to it."
}
]
},
"LEARNER_GROUP_VIEWER": {
"ROUTE": "learner-group/:learner_group_id",
"TITLE": "I18N_LEARNER_GROUP_PAGE_TITLE",
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/access_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get(self) -> None:
pass


class ViewLearnerGroupPageAccessValidationHandler(
class LearnerGroupPageAccessValidationHandler(
base.BaseHandler[Dict[str, str], Dict[str, str]]
):
"""Validates access to view learner group page."""
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/access_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_normal_user_can_manage_account(self) -> None:
self.logout()


class ViewLearnerGroupPageAccessValidationHandlerTests(
class LearnerGroupPageAccessValidationHandlerTests(
test_utils.GenericTestBase
):

Expand Down
38 changes: 0 additions & 38 deletions core/controllers/learner_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,44 +761,6 @@ def get(self) -> None:
})


class EditLearnerGroupPage(
base.BaseHandler[Dict[str, str], Dict[str, str]]
):
"""Page for editing a learner group."""

URL_PATH_ARGS_SCHEMAS = {
'group_id': {
'schema': {
'type': 'basestring',
'validators': [{
'id': 'is_regex_matched',
'regex_pattern': constants.LEARNER_GROUP_ID_REGEX
}]
}
}
}
HANDLER_ARGS_SCHEMAS: Dict[str, Dict[str, str]] = {
'GET': {}
}

@acl_decorators.can_access_learner_groups
def get(self, group_id: str) -> None:
"""Handles GET requests."""
assert self.user_id is not None
if not learner_group_services.is_learner_group_feature_enabled(
self.user_id
):
raise self.PageNotFoundException

is_valid_request = learner_group_services.is_user_facilitator(
self.user_id, group_id)

if not is_valid_request:
raise self.PageNotFoundException

self.render_template('edit-learner-group-page.mainpage.html')


class LearnerGroupLearnersInfoHandler(
base.BaseHandler[Dict[str, str], Dict[str, str]]
):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2023 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Guard that redirects user to 401 error page
* if the user is not a super admin.
*/

import { Location } from '@angular/common';
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot,
} from '@angular/router';

import { AppConstants } from 'app.constants';
import { AccessValidationBackendApiService } from 'pages/oppia-root/routing/access-validation-backend-api.service';
import { ContextService } from 'services/context.service';

@Injectable({
providedIn: 'root'
})
export class AdminAuthGuard implements CanActivate {
constructor(
private accessValidationBackendApiService:
AccessValidationBackendApiService,
private contextService: ContextService,
private router: Router,
private location: Location
) {}

async canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Promise<boolean> {
return new Promise<boolean>((resolve) => {
let learnerGroupId = this.contextService.getLearnerGroupId();
DubeySandeep marked this conversation as resolved.
Show resolved Hide resolved
this.accessValidationBackendApiService
.doesLearnerGroupExist(learnerGroupId)
.then(() => {
resolve(true);
})
.catch((err) => {
this.router.navigate(
[`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND.ERROR.ROUTE}/401`])
.then(() => {
this.location.replaceState(state.url);
resolve(false);
});
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<oppia-angular-root>
<oppia-edit-learner-group-page></oppia-edit-learner-group-page>
</oppia-angular-root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Admin page root component.
*/

import { Component } from '@angular/core';
import { AppConstants } from 'app.constants';
import { BaseRootComponent, MetaTagData } from 'pages/base-root.component';

@Component({
selector: 'oppia-admin-page-root',
templateUrl: './admin-page-root.component.html',
})
export class AdminPageRootComponent extends BaseRootComponent {
title: string = AppConstants.
PAGES_REGISTERED_WITH_FRONTEND.LEARNER_GROUP_EDITOR.TITLE;

meta: MetaTagData[] =
AppConstants.PAGES_REGISTERED_WITH_FRONTEND.LEARNER_GROUP_EDITOR.META as
unknown as Readonly<MetaTagData>[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import { Component, OnDestroy, OnInit } from '@angular/core';
import { downgradeComponent } from '@angular/upgrade/static';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';

Expand Down Expand Up @@ -99,7 +98,3 @@ export class EditLearnerGroupPageComponent implements OnInit, OnDestroy {
this.directiveSubscriptions.unsubscribe();
}
}

angular.module('oppia').directive(
'oppiaEditLearnerGroupPage',
downgradeComponent({component: EditLearnerGroupPageComponent}));

This file was deleted.

4 changes: 1 addition & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get_redirect_route(
get_redirect_route(
r'%s/does_learner_group_exist/<learner_group_id>' %
feconf.ACCESS_VALIDATION_HANDLER_PREFIX,
access_validators.ViewLearnerGroupPageAccessValidationHandler),
access_validators.LearnerGroupPageAccessValidationHandler),

get_redirect_route(r'%s' % feconf.ADMIN_URL, oppia_root.OppiaRootPage),
get_redirect_route(r'/adminhandler', admin.AdminHandler),
Expand Down Expand Up @@ -1113,8 +1113,6 @@ def get_redirect_route(
get_redirect_route(
r'/exit_learner_group_handler/<learner_group_id>',
learner_group.ExitLearnerGroupHandler),
get_redirect_route(
r'/edit-learner-group/<group_id>', learner_group.EditLearnerGroupPage),
get_redirect_route(
r'/user_progress_in_stories_chapters_handler/<username>',
learner_group.LearnerStoriesChaptersProgressHandler),
Expand Down