def _view_registries_landing_page(campaign=None, **kwargs): """Landing page for the various registrations""" auth = kwargs['auth'] = Auth.from_kwargs(request.args.to_dict(), kwargs) is_logged_in = kwargs['auth'].logged_in if is_logged_in: # Using contributor_to instead of contributor_to_or_group_member. # You need to be an admin contributor to register a node registerable_nodes = [ node for node in auth.user.contributor_to if node.has_permission(user=auth.user, permission=ADMIN) ] has_projects = bool(registerable_nodes) else: has_projects = False if campaign == 'registered_report': campaign_url_param = 'osf-registered-reports' elif campaign == 'prereg_challenge' or campaign == 'prereg': campaign_url_param = 'prereg' else: campaign_url_param = '' return { 'is_logged_in': is_logged_in, 'has_draft_registrations': bool(utils.drafts_for_user(auth.user, campaign)), 'has_projects': has_projects, 'campaign_long': utils.REG_CAMPAIGNS.get(campaign), 'campaign_short': campaign, 'sign_up_url': util.web_url_for('auth_register', _absolute=True, campaign=campaign_url_param, next=request.url), }
def test_drafts_for_user_omits_registered(self): prereg_schema = RegistrationSchema.objects.get(name='Prereg Challenge', schema_version=2) d1 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema) d2 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema) d3 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema) d1.registered_node = factories.RegistrationFactory() d1.save() drafts = drafts_for_user(self.user, 'prereg') for d in drafts: assert_in(d._id, (d2._id, d3._id)) assert_not_equal(d._id, d1._id)
def _view_registries_landing_page(campaign=None, **kwargs): """Landing page for the various registrations""" auth = kwargs['auth'] = Auth.from_kwargs(request.args.to_dict(), kwargs) is_logged_in = kwargs['auth'].logged_in if is_logged_in: registerable_nodes = [ node for node in auth.user.contributor_to if node.has_permission(user=auth.user, permission='admin') ] has_projects = bool(registerable_nodes) else: has_projects = False return { 'is_logged_in': is_logged_in, 'has_draft_registrations': bool(utils.drafts_for_user(auth.user, campaign)), 'has_projects': has_projects, 'campaign_long': utils.REG_CAMPAIGNS.get(campaign), 'campaign_short': campaign }
def test_drafts_for_user_omits_registered(self): prereg_schema = MetaSchema.objects.get(name='Prereg Challenge', schema_version=2) d1 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema ) d2 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema ) d3 = factories.DraftRegistrationFactory( initiator=self.user, registration_schema=prereg_schema ) d1.registered_node = factories.RegistrationFactory() d1.save() drafts = drafts_for_user(self.user, 'prereg') for d in drafts: assert_in(d._id, (d2._id, d3._id)) assert_not_equal(d._id, d1._id)
def draft_registrations(auth, **kwargs): """API endpoint; returns various draft registrations the user can resume their draft""" campaign = kwargs.get('campaign', None) drafts = utils.drafts_for_user(auth.user, campaign) return { 'draftRegistrations': [ { 'dateUpdated': iso8601format(draft.datetime_updated), 'dateInitiated': iso8601format(draft.datetime_initiated), 'node': { 'title': draft.branched_from.title, }, 'initiator': { 'name': draft.initiator.fullname, }, 'url': draft.branched_from.web_url_for( 'edit_draft_registration_page', draft_id=draft._id, ), } for draft in drafts ], }
def draft_registrations(auth, **kwargs): """API endpoint; returns various draft registrations the user can resume their draft""" campaign = kwargs.get('campaign', None) drafts = utils.drafts_for_user(auth.user, campaign) return { 'draftRegistrations': [{ 'dateUpdated': iso8601format(draft.datetime_updated), 'dateInitiated': iso8601format(draft.datetime_initiated), 'node': { 'title': draft.branched_from.title, }, 'initiator': { 'name': draft.initiator.fullname, }, 'url': draft.branched_from.web_url_for( 'edit_draft_registration_page', draft_id=draft._id, ), } for draft in drafts], }