def _RegisterRedirects(self): """Register redirects among pages inside monorail.""" redirect = registerpages_helpers.MakeRedirect('/hosting/') self._SetupServlets({ '/hosting': redirect, '/p': redirect, '/p/': redirect, '/u': redirect, '/u/': redirect, '/': redirect, }) redirect = registerpages_helpers.MakeRedirectInScope( urls.PEOPLE_LIST, 'p') self._SetupProjectServlets({ '/people': redirect, '/people/': redirect, }) redirect = registerpages_helpers.MakeRedirect(urls.GROUP_LIST) self._SetupServlets({'/g': redirect}) group_redir = registerpages_helpers.MakeRedirectInScope( urls.USER_PROFILE, 'g') self._SetupGroupServlets({'': group_redir})
def testMakeRedirectInScope_KeepQueryString(self): factory = registerpages_helpers.MakeRedirectInScope( '/', 'p', keep_qs=True) request = webapp2.Request.blank( path='/p/foo?q=1', headers={'Host': 'example.com'}) response = webapp2.Response() redirector = factory(request, response) redirector.get() self.assertEqual(response.location, '//example.com/p/foo/?q=1') self.assertEqual(response.status, '302 Moved Temporarily')
def testMakeRedirectInScope_Temporary(self): factory = registerpages_helpers.MakeRedirectInScope( '/', 'p', permanent=False) request = webapp2.Request.blank( path='/p/foo', headers={'Host': 'example.com'}) response = webapp2.Response() redirector = factory(request, response) redirector.get() self.assertEqual(response.location, '//example.com/p/foo/') self.assertEqual(response.status, '302 Moved Temporarily')
def testMakeRedirectInScope_Normal(self): factory = registerpages_helpers.MakeRedirectInScope('/', 'p') # Non-dasher, normal case request = webapp2.Request.blank( path='/p/foo', headers={'Host': 'example.com'}) response = webapp2.Response() redirector = factory(request, response) redirector.get() self.assertEqual(response.location, '//example.com/p/foo/') self.assertEqual(response.status, '301 Moved Permanently')
def _RegisterSitewideHandlers(self): """Register page and form handlers that aren't associated with projects.""" self._SetupServlets({ urls.PROJECT_CREATE: projectcreate.ProjectCreate, # The user settings page is a site-wide servlet, not under /u/. urls.USER_SETTINGS: usersettings.UserSettings, urls.HOSTING_HOME: hostinghome.HostingHome, urls.GROUP_CREATE: groupcreate.GroupCreate, urls.GROUP_LIST: grouplist.GroupList, urls.GROUP_DELETE: grouplist.GroupList, urls.HOTLIST_CREATE: hotlistcreate.HotlistCreate, urls.BAN_SPAMMER_TASK: banspammer.BanSpammerTask, urls.WIPEOUT_SYNC_CRON: deleteusers.WipeoutSyncCron, urls.SEND_WIPEOUT_USER_LISTS_TASK: deleteusers.SendWipeoutUserListsTask, urls.DELETE_WIPEOUT_USERS_TASK: deleteusers.DeleteWipeoutUsersTask, urls.DELETE_USERS_TASK: deleteusers.DeleteUsersTask, }) self._SetupUserServlets({ urls.USER_PROFILE: userprofile.UserProfile, urls.USER_PROFILE_POLYMER: userprofile.UserProfilePolymer, urls.BAN_USER: userprofile.BanUser, urls.BAN_SPAMMER: banspammer.BanSpammer, urls.USER_CLEAR_BOUNCING: userclearbouncing.UserClearBouncing, urls.USER_UPDATES_PROJECTS: userupdates.UserUpdatesProjects, urls.USER_UPDATES_DEVELOPERS: userupdates.UserUpdatesDevelopers, urls.USER_UPDATES_MINE: userupdates.UserUpdatesIndividual, }) self._SetupUserHotlistServlets({ urls.HOTLIST_ISSUES: hotlistissues.HotlistIssues, urls.HOTLIST_ISSUES_CSV: hotlistissuescsv.HotlistIssuesCsv, urls.HOTLIST_PEOPLE: hotlistpeople.HotlistPeopleList, urls.HOTLIST_DETAIL: hotlistdetails.HotlistDetails, urls.HOTLIST_RERANK_JSON: rerankhotlist.RerankHotlistIssue, }) profile_redir = registerpages_helpers.MakeRedirectInScope( urls.USER_PROFILE, 'u') self._SetupUserServlets({'': profile_redir}) self._SetupGroupServlets({ urls.GROUP_DETAIL: groupdetail.GroupDetail, urls.GROUP_ADMIN: groupadmin.GroupAdmin, })
def _RegisterIssueHandlers(self): """Register page and form handlers for the issue tracker.""" self._SetupServlets({ # Note: there is both a site-wide and per-project issue list. urls.ISSUE_LIST: issuelist.IssueList, # Note: the following are at URLs that are not externaly accessible. urls.BACKEND_SEARCH: backendsearch.BackendSearch, urls.BACKEND_NONVIEWABLE: backendnonviewable.BackendNonviewable, urls.RECOMPUTE_DERIVED_FIELDS_TASK: filterrules.RecomputeDerivedFieldsTask, urls.REINDEX_QUEUE_CRON: filterrules.ReindexQueueCron, urls.NOTIFY_ISSUE_CHANGE_TASK: notify.NotifyIssueChangeTask, urls.NOTIFY_BLOCKING_CHANGE_TASK: notify.NotifyBlockingChangeTask, urls.NOTIFY_BULK_CHANGE_TASK: notify.NotifyBulkChangeTask, urls.NOTIFY_APPROVAL_CHANGE_TASK: notify.NotifyApprovalChangeTask, urls.OUTBOUND_EMAIL_TASK: notify.OutboundEmailTask, urls.SPAM_DATA_EXPORT_TASK: spammodel.TrainingDataExportTask, urls.DATE_ACTION_CRON: dateaction.DateActionCron, urls.SPAM_TRAINING_CRON: spamtraining.TrainSpamModelCron, urls.ISSUE_DATE_ACTION_TASK: dateaction.IssueDateActionTask, urls.COMPONENT_DATA_EXPORT_CRON: componentexport.ComponentTrainingDataExport, urls.COMPONENT_DATA_EXPORT_TASK: componentexport.ComponentTrainingDataExportTask, urls.FLT_ISSUE_CONVERSION_TASK: fltconversion.FLTConvertTask, }) self._SetupProjectServlets({ urls.ISSUE_APPROVAL: webcomponentspage.IssueDetailRedirect, urls.ISSUE_LIST: issuelist.IssueList, urls.ISSUE_NEW_GRID: webcomponentspage.WebComponentsPage, urls.ISSUE_LIST_CSV: issuelistcsv.IssueListCsv, urls.ISSUE_REINDEX: issuereindex.IssueReindex, urls.ISSUE_DETAIL_FLIPPER_NEXT: issuedetailezt.FlipperNext, urls.ISSUE_DETAIL_FLIPPER_PREV: issuedetailezt.FlipperPrev, urls.ISSUE_DETAIL_FLIPPER_LIST: issuedetailezt.FlipperList, urls.ISSUE_DETAIL_FLIPPER_INDEX: issuedetailezt.FlipperIndex, urls.ISSUE_DETAIL_LEGACY: registerpages_helpers.MakeRedirectInScope(urls.ISSUE_DETAIL, 'p', keep_qs=True), urls.ISSUE_ENTRY: issueentry.IssueEntry, urls.ISSUE_ENTRY_AFTER_LOGIN: issueentryafterlogin.IssueEntryAfterLogin, urls.ISSUE_TIPS: issuetips.IssueSearchTips, urls.ISSUE_ATTACHMENT: issueattachment.AttachmentPage, urls.ISSUE_ATTACHMENT_TEXT: issueattachmenttext.AttachmentText, urls.ISSUE_BULK_EDIT: issuebulkedit.IssueBulkEdit, urls.COMPONENT_CREATE: componentcreate.ComponentCreate, urls.COMPONENT_DETAIL: componentdetail.ComponentDetail, urls.FIELD_CREATE: fieldcreate.FieldCreate, urls.FIELD_DETAIL: fielddetail.FieldDetail, urls.TEMPLATE_CREATE: templatecreate.TemplateCreate, urls.TEMPLATE_DETAIL: templatedetail.TemplateDetail, urls.WIKI_LIST: redirects.WikiRedirect, urls.WIKI_PAGE: redirects.WikiRedirect, urls.SOURCE_PAGE: redirects.SourceRedirect, urls.ADMIN_STATUSES: issueadmin.AdminStatuses, urls.ADMIN_LABELS: issueadmin.AdminLabels, urls.ADMIN_RULES: issueadmin.AdminRules, urls.ADMIN_TEMPLATES: issueadmin.AdminTemplates, urls.ADMIN_COMPONENTS: issueadmin.AdminComponents, urls.ADMIN_VIEWS: issueadmin.AdminViews, urls.ISSUE_ORIGINAL: issueoriginal.IssueOriginal, urls.ISSUE_EXPORT: issueexport.IssueExport, urls.ISSUE_EXPORT_JSON: issueexport.IssueExportJSON, urls.ISSUE_IMPORT: issueimport.IssueImport, urls.SPAM_MODERATION_QUEUE: spam.ModerationQueue, }) # GETs for /issues/detail are now handled by the web components page. base = '/p/<project_name:%s>' % self._PROJECT_NAME_REGEX self._AddRoute(base + urls.ISSUE_DETAIL, webcomponentspage.WebComponentsPage, 'GET') self._SetupUserServlets({ urls.SAVED_QUERIES: savedqueries.SavedQueries, urls.HOTLISTS: userhotlists.UserHotlists, }) user_hotlists_redir = registerpages_helpers.MakeRedirectInScope( urls.HOTLISTS, 'u', keep_qs=True) self._SetupUserServlets({ '/hotlists/': user_hotlists_redir, }) # These servlets accept POST, but never write to the database, so they can # still be used when the site is read-only. self._SetupProjectServlets( { urls.ISSUE_ADVSEARCH: issueadvsearch.IssueAdvancedSearch, }, post_does_write=False) list_redir = registerpages_helpers.MakeRedirectInScope(urls.ISSUE_LIST, 'p', keep_qs=True) self._SetupProjectServlets({ '': list_redir, '/': list_redir, '/issues': list_redir, '/issues/': list_redir, }) list_redir = registerpages_helpers.MakeRedirect(urls.ISSUE_LIST) self._SetupServlets({ '/issues': list_redir, '/issues/': list_redir, })
def _RegisterSitewideHandlers(self): """Register page and form handlers that aren't associated with projects.""" self._SetupServlets({ urls.PROJECT_CREATE: projectcreate.ProjectCreate, urls.CHECK_PROJECT_NAME_JSON: projectcreate.CheckProjectNameJSON, # The user settings page is a site-wide servlet, not under /u/. urls.USER_SETTINGS: usersettings.UserSettings, urls.USER_PROJECTS_JSON: userprojects.ProjectsJsonFeed, urls.USER_HOTLISTS_JSON: userhotlistsmenu.HotlistsJsonFeed, urls.HOSTING_HOME: hostinghome.HostingHome, urls.STARS_JSON: stars.SetStarsFeed, urls.CUES_JSON: cues.SetCuesFeed, urls.GROUP_CREATE: groupcreate.GroupCreate, urls.GROUP_LIST: grouplist.GroupList, urls.GROUP_DELETE: grouplist.GroupList, urls.HOTLIST_CREATE: hotlistcreate.HotlistCreate, urls.ADD_ISSUES_TO_HOTLIST: issueaddtohotlist.AddToHotlist, urls.BAN_SPAMMER_TASK: banspammer.BanSpammerTask, }) self._SetupUserServlets({ urls.USER_PROFILE: userprofile.UserProfile, urls.BAN_USER: userprofile.BanUser, urls.BAN_SPAMMER: banspammer.BanSpammer, urls.USER_CLEAR_BOUNCING: userclearbouncing.UserClearBouncing, urls.USER_UPDATES_PROJECTS: userupdates.UserUpdatesProjects, urls.USER_UPDATES_DEVELOPERS: userupdates.UserUpdatesDevelopers, urls.USER_UPDATES_MINE: userupdates.UserUpdatesIndividual, }) self._SetupUserHotlistServlets({ urls.HOTLIST_ISSUES: hotlistissues.HotlistIssues, urls.HOTLIST_ISSUES_CSV: hotlistissuescsv.HotlistIssuesCsv, urls.HOTLIST_PEOPLE: hotlistpeople.HotlistPeopleList, urls.HOTLIST_DETAIL: hotlistdetails.HotlistDetails, urls.HOTLIST_RERANK_JSON: rerankhotlist.RerankHotlistIssue, urls.HOTLIST_NEW_NOTES_JSON: updatehotlistitems.UpdateHotlistIssueNote, }) profile_redir = registerpages_helpers.MakeRedirectInScope( urls.USER_PROFILE, 'u') self._SetupUserServlets({'': profile_redir}) self._SetupGroupServlets({ urls.GROUP_DETAIL: groupdetail.GroupDetail, urls.GROUP_ADMIN: groupadmin.GroupAdmin, })
def _RegisterIssueHandlers(self): """Register page and form handlers for the issue tracker.""" self._SetupServlets({ # Note: there is both a site-wide and per-project issue list. urls.ISSUE_LIST: issuelist.IssueList, # Note: the following are at URLs that are not externaly accessible. urls.BACKEND_SEARCH: backendsearch.BackendSearch, urls.BACKEND_NONVIEWABLE: backendnonviewable.BackendNonviewable, urls.RECOMPUTE_DERIVED_FIELDS_TASK: filterrules.RecomputeDerivedFieldsTask, urls.REINDEX_QUEUE_CRON: filterrules.ReindexQueueCron, urls.NOTIFY_ISSUE_CHANGE_TASK: notify.NotifyIssueChangeTask, urls.NOTIFY_BLOCKING_CHANGE_TASK: notify.NotifyBlockingChangeTask, urls.NOTIFY_BULK_CHANGE_TASK: notify.NotifyBulkChangeTask, urls.OUTBOUND_EMAIL_TASK: notify.OutboundEmailTask, urls.SPAM_DATA_EXPORT_TASK: spammodel.TrainingDataExportTask, urls.DATE_ACTION_CRON: dateaction.DateActionCron, urls.ISSUE_DATE_ACTION_TASK: dateaction.IssueDateActionTask, }) self._SetupProjectServlets({ urls.ISSUE_LIST: issuelist.IssueList, urls.ISSUE_LIST_CSV: issuelistcsv.IssueListCsv, urls.ISSUE_REINDEX: issuereindex.IssueReindex, urls.ISSUE_DETAIL: issuedetail.IssueDetail, urls.ISSUE_COMMENT_DELETION_JSON: issuedetail.IssueCommentDeletion, urls.ISSUE_ATTACHMENT_DELETION_JSON: issueattachment.IssueAttachmentDeletion, urls.ISSUE_FLAGSPAM_JSON: spam.FlagSpamForm, urls.ISSUE_SETSTAR_JSON: issuedetail.SetStarForm, urls.ISSUE_DELETE_JSON: issuedetail.IssueDeleteForm, urls.ISSUE_PRESUBMIT_JSON: issuepresubmit.IssuePresubmitJSON, urls.ISSUE_ENTRY: issueentry.IssueEntry, urls.ISSUE_ENTRY_AFTER_LOGIN: issueentryafterlogin.IssueEntryAfterLogin, urls.ISSUE_OPTIONS_JSON: issueoptions.IssueOptionsJSON, urls.ISSUE_TIPS: issuetips.IssueSearchTips, urls.ISSUE_ATTACHMENT: issueattachment.AttachmentPage, urls.ISSUE_ATTACHMENT_TEXT: issueattachmenttext.AttachmentText, urls.ISSUE_BULK_EDIT: issuebulkedit.IssueBulkEdit, urls.COMPONENT_CHECKNAME_JSON: componentcreate.CheckComponentNameJSON, urls.COMPONENT_CREATE: componentcreate.ComponentCreate, urls.COMPONENT_DETAIL: componentdetail.ComponentDetail, urls.FIELD_CHECKNAME_JSON: fieldcreate.CheckFieldNameJSON, urls.FIELD_CREATE: fieldcreate.FieldCreate, urls.FIELD_DETAIL: fielddetail.FieldDetail, urls.WIKI_LIST: redirects.WikiRedirect, urls.WIKI_PAGE: redirects.WikiRedirect, urls.SOURCE_PAGE: redirects.SourceRedirect, urls.ADMIN_STATUSES: issueadmin.AdminStatuses, urls.ADMIN_LABELS: issueadmin.AdminLabels, urls.ADMIN_RULES: issueadmin.AdminRules, urls.ADMIN_TEMPLATES: issueadmin.AdminTemplates, urls.ADMIN_COMPONENTS: issueadmin.AdminComponents, urls.ADMIN_VIEWS: issueadmin.AdminViews, urls.ISSUE_ORIGINAL: issueoriginal.IssueOriginal, urls.ISSUE_EXPORT: issueexport.IssueExport, urls.ISSUE_EXPORT_JSON: issueexport.IssueExportJSON, urls.ISSUE_IMPORT: issueimport.IssueImport, urls.SPAM_MODERATION_QUEUE: spam.ModerationQueue, urls.ISSUE_RERANK_BLOCKED_ON: issuererank.IssueRerank, }) self._SetupUserServlets({ urls.SAVED_QUERIES: savedqueries.SavedQueries, urls.HOTLISTS: userhotlists.UserHotlists, }) user_hotlists_redir = registerpages_helpers.MakeRedirectInScope( urls.HOTLISTS, 'u', keep_qs=True) self._SetupUserServlets({ '/hotlists/': user_hotlists_redir, }) # These servlets accept POST, but never write to the database, so they can # still be used when the site is read-only. self._SetupProjectServlets( { urls.ISSUE_ADVSEARCH: issueadvsearch.IssueAdvancedSearch, }, post_does_write=False) list_redir = registerpages_helpers.MakeRedirectInScope(urls.ISSUE_LIST, 'p', keep_qs=True) self._SetupProjectServlets({ '': list_redir, '/': list_redir, '/issues': list_redir, '/issues/': list_redir, }) list_redir = registerpages_helpers.MakeRedirect(urls.ISSUE_LIST) self._SetupServlets({ '/issues': list_redir, '/issues/': list_redir, })