class SubscribedTasksPage(base.GCIRequestHandler): """View for the list of the tasks the specified profile is subscribed to.""" def templatePath(self): return 'modules/gci/subscribed_tasks/subscribed_tasks.html' def djangoURLPatterns(self): return [ gci_url_patterns.url(r'subscribed_tasks/%s$' % url_patterns.PROFILE, self, name=url_names.GCI_SUBSCRIBED_TASKS), ] access_checker = access.ConjuctionAccessChecker( [access.IS_URL_USER_ACCESS_CHECKER, access.HAS_PROFILE_ACCESS_CHECKER]) def jsonContext(self, data, check, mutator): return SubscribedTasksList(data).getListData().content() def context(self, data, check, mutator): return { 'page_name': 'Tasks %s is subscribed to' % data.url_ndb_profile.public_name, 'tasks_list': SubscribedTasksList(data), }
def testLastCheckerFails(self): """Tests that checker fails if the last sub-checker fails.""" checkers = [access.AllAllowedAccessChecker() for _ in xrange(4)] checkers.append(NoneAllowedAccessChecker('last')) access_checker = access.ConjuctionAccessChecker(checkers) with self.assertRaises(exception.UserError) as context: access_checker.checkAccess(None, None) self.assertEqual(context.exception.message, 'last')
class OrgApplicationSubmitPage(base.GSoCRequestHandler): """View to submit application to a program by organization representatives.""" access_checker = access.ConjuctionAccessChecker([ access.IS_USER_ORG_ADMIN_FOR_NDB_ORG, access.UrlOrgStatusAccessChecker( [org_model.Status.APPLYING, org_model.Status.PRE_ACCEPTED, org_model.Status.PRE_REJECTED])]) def djangoURLPatterns(self): """See base.RequestHandler.djangoURLPatterns for specification.""" return [ soc_url_patterns.url( r'org/application/submit/%s$' % url_patterns.ORG, self, name=urls.UrlNames.ORG_APPLICATION_SUBMIT)] def templatePath(self): """See base.RequestHandler.templatePath for specification.""" return 'modules/gsoc/org_app/take.html' def context(self, data, check, mutator): """See base.RequestHandler.context for specification.""" application = org_logic.getApplicationResponse(data.url_ndb_org.key) form_data = application.to_dict() if application else None form = gsoc_forms.SurveyTakeForm( survey=data.org_app, data=data.POST or form_data) return { 'page_name': ORG_APPLICATION_SUBMIT_PAGE_NAME, 'forms': [form], 'error': bool(form.errors), 'tabs': tabs.orgTabs(data, selected_tab_id=tabs.ORG_APP_RESPONSE_TAB_ID) } def post(self, data, check, mutator): """See base.RequestHandler.post for specification.""" form = gsoc_forms.SurveyTakeForm(survey=data.org_app, data=data.POST) if not form.is_valid(): # TODO(nathaniel): problematic self-use. return self.get(data, check, mutator) else: properties = form.getSurveyResponseProperties() setApplicationResponse( data.url_ndb_org.key, data.org_app.key(), properties) url = links.LINKER.organization( data.url_ndb_org.key, urls.UrlNames.ORG_APPLICATION_SUBMIT) return http.HttpResponseRedirect(url)
def testForAllPassingCheckers(self): """Tests that checker passes if all sub-checkers pass.""" checkers = [access.AllAllowedAccessChecker() for _ in xrange(5)] access_checker = access.ConjuctionAccessChecker(checkers) access_checker.checkAccess(None, None)
class OrgProfileCreatePage(base.GSoCRequestHandler): """View to create organization profile.""" access_checker = access.ConjuctionAccessChecker([ access.NON_STUDENT_PROFILE_ACCESS_CHECKER, access.ORG_SIGNUP_ACTIVE_ACCESS_CHECKER]) def templatePath(self): """See base.RequestHandler.templatePath for specification.""" return 'summerofcode/organization/org_profile_edit.html' def djangoURLPatterns(self): """See base.RequestHandler.djangoURLPatterns for specification.""" return [ soc_url_patterns.url( r'org/profile/create/%s$' % url_patterns.PROGRAM, self, name=urls.UrlNames.ORG_PROFILE_CREATE)] def context(self, data, check, mutator): """See base.RequestHandler.context for specification.""" form = _formToCreateOrgProfile(request_data=data, data=data.POST or None) return { 'page_name': ORG_PROFILE_CREATE_PAGE_NAME, 'description': data.org_app.content, 'forms': [form], 'error': bool(form.errors) } def post(self, data, check, mutator): """See base.RequestHandler.post for specification.""" form = _formToCreateOrgProfile(request_data=data, data=data.POST) if not form.is_valid(): # TODO(nathaniel): problematic self-use. return self.get(data, check, mutator) else: contact_properties = form.getContactProperties() result = contact_logic.createContact(**contact_properties) if not result: raise exception.BadRequest(message=result.extra) else: org_properties = form.getOrgProperties() org_properties['contact'] = result.extra # org_id is a special property org_id = org_properties['org_id'] del org_properties['org_id'] result = createOrganizationTxn( data, org_id, data.program.key(), org_properties, [data.ndb_profile.key, form.cleaned_data['backup_admin'].key], data.models) if not result: raise exception.BadRequest(message=result.extra) else: url = links.LINKER.organization( result.extra.key, urls.UrlNames.ORG_APPLICATION_SUBMIT) return http.HttpResponseRedirect(url)
if not result: raise exception.BadRequest(message=result.extra) else: org_properties = form.getOrgProperties() org_properties['contact'] = result.extra updateOrganizationTxn(data.url_ndb_org.key, org_properties) url = links.LINKER.organization( data.url_ndb_org.key, urls.UrlNames.ORG_PROFILE_EDIT) return http.HttpResponseRedirect(url) ORG_PREFERENCES_EDIT_PAGE_ACCESS_CHECKER = access.ConjuctionAccessChecker([ access.IS_USER_ORG_ADMIN_FOR_NDB_ORG, access.UrlOrgStatusAccessChecker([org_model.Status.ACCEPTED])]) class OrgPreferencesEditPage(base.GSoCRequestHandler): """View to edit organization preferences.""" access_checker = ORG_PREFERENCES_EDIT_PAGE_ACCESS_CHECKER def templatePath(self): """See base.RequestHandler.templatePath for specification.""" return 'modules/gsoc/org_profile/base.html' def djangoURLPatterns(self): """See base.RequestHandler.djangoURLPatterns for specification.""" return [ soc_url_patterns.url(
from melange.request import access from melange.views import connection as connection_view from summerofcode.request import error from summerofcode.request import links from summerofcode.request import render from summerofcode.views.helper import urls as soc_urls START_CONNECTION_AS_ORG = connection_view.StartConnectionAsOrg( gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER, error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR, soc_urls.UrlNames, 'summerofcode/connection/start_connection.html') START_CONNECTION_AS_USER_ACCESS_CHECKER = access.ConjuctionAccessChecker([ access.PROGRAM_ACTIVE_ACCESS_CHECKER, access.NON_STUDENT_PROFILE_ACCESS_CHECKER, access.UrlOrgStatusAccessChecker([org_model.Status.ACCEPTED]), connection_view.NoConnectionExistsAccessChecker(soc_urls.UrlNames) ]) START_CONNECTION_AS_USER = connection_view.StartConnectionAsUser( gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER, error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR, soc_urls.UrlNames, 'modules/gsoc/form_base.html', START_CONNECTION_AS_USER_ACCESS_CHECKER) LIST_CONNECTION_FOR_ORG_ADMIN = connection_view.ListConnectionsForOrgAdmin( gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER, error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR, soc_urls.UrlNames, 'summerofcode/connection/connection_list.html') LIST_CONNECTION_FOR_USER = connection_view.ListConnectionsForUser(