Esempio n. 1
0
  def testInviteOrgAdmin(self):
    # test GET
    self.data.createOrgAdmin(self.org)
    url = '/gsoc/invite/org_admin/' + self.org.key().name()
    response = self.client.get(url)
    self.assertInviteTemplatesUsed(response)

    # create other user to send invite to
    other_data = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_user = other_data.createOtherUser('*****@*****.**')
    other_data.createProfile()

    # test POST
    override = {'link_id': other_user.link_id, 'status': 'pending',
                'role': 'org_admin', 'user': other_user, 'group': self.org,
                'type': 'Invitation'}
    response, properties = self.modelPost(url, Request, override)

    invitation = Request.all().get()
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)

    invitation.delete()
    override['link_id'] = '*****@*****.**'
    response, properties = self.modelPost(url, Request, override)

    invitation = Request.all().get()
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)
Esempio n. 2
0
  def checkAccess(self):
    self.check.isProfileActive()
    
    id = int(self.data.kwargs['id'])
    self.data.invite = self.data.request_entity = Request.get_by_id(id)
    self.check.isRequestPresent(self.data.request_entity, id)

    self.data.organization = self.data.request_entity.group
    self.data.invited_user = self.data.requester = self.data.request_entity.user

    if self.data.POST:
      self.data.action = self.data.POST['action']

      if self.data.action == self.ACTIONS['accept']:
        self.check.canRespondToRequest()
      elif self.data.action == self.ACTIONS['reject']:
        self.check.canRespondToRequest()
      elif self.data.action == self.ACTIONS['resubmit']:
        self.check.canResubmitRequest()
      # withdraw action
    else:
      self.check.canViewRequest()

    self.mutator.canRespondForUser()

    key_name = '/'.join([
        self.data.program.key().name(),
        self.data.requester.link_id])
    self.data.requester_profile = GSoCProfile.get_by_key_name(
        key_name, parent=self.data.requester)
Esempio n. 3
0
    def checkAccess(self):
        self.check.isProfileActive()

        id = int(self.data.kwargs['id'])
        self.data.invite = self.data.request_entity = Request.get_by_id(id)
        self.check.isRequestPresent(self.data.request_entity, id)

        self.data.organization = self.data.request_entity.group
        self.data.invited_user = self.data.requester = self.data.request_entity.user

        if self.data.POST:
            self.data.action = self.data.POST['action']

            if self.data.action == self.ACTIONS['accept']:
                self.check.canRespondToRequest()
            elif self.data.action == self.ACTIONS['reject']:
                self.check.canRespondToRequest()
            elif self.data.action == self.ACTIONS['resubmit']:
                self.check.canResubmitRequest()
            # withdraw action
        else:
            self.check.canViewRequest()

        self.mutator.canRespondForUser()

        key_name = '/'.join(
            [self.data.program.key().name(), self.data.requester.link_id])
        self.data.requester_profile = GSoCProfile.get_by_key_name(
            key_name, parent=self.data.requester)
Esempio n. 4
0
  def checkAccess(self):
    self.check.isProfileActive()
    
    invite_id = int(self.data.kwargs['id'])
    self.data.invite = Request.get_by_id(invite_id)
    self.check.isInvitePresent(invite_id)

    self.data.organization = self.data.invite.org
    self.data.invited_user = self.data.invite.user

    if self.data.POST:
      self.data.action = self.data.POST['action']

      if self.data.action == self.ACTIONS['accept']:
        self.check.canRespondToInvite()
      elif self.data.action == self.ACTIONS['reject']:
        self.check.canRespondToInvite()
      elif self.data.action == self.ACTIONS['resubmit']:
        self.check.canResubmitInvite()
    else:
      self.check.canViewInvite()

    self.mutator.canRespondForUser()

    if self.data.user.key() == self.data.invited_user.key():
      self.data.invited_profile = self.data.profile
      return

    key_name = '/'.join([
        self.data.program.key().name(),
        self.data.invited_user.link_id])
    self.data.invited_profile = GSoCProfile.get_by_key_name(
        key_name, parent=self.data.invited_user)
Esempio n. 5
0
  def _requestQuery(self, organization):
    """Returns a query to retrieve a Request for this user.
    """
    if isinstance(organization, db.Model):
      organization = organization.key()

    from soc.models.request import Request
    query = Request.all()
    query.filter('user', self.user)
    query.filter('org', organization)

    return query
Esempio n. 6
0
  def testRequestMentor(self):
    # test GET
    self.data.createProfile()
    url = '/gsoc/request/' + self.org.key().name()
    response = self.client.get(url)
    self.assertRequestTemplatesUsed(response)

    # test POST
    override = {'status': 'pending', 'role': 'mentor', 'type': 'Request',
                'user': self.data.user, 'group': self.org}
    response, properties = self.modelPost(url, Request, override)

    request = Request.all().get()
    self.assertPropertiesEqual(properties, request)
Esempio n. 7
0
  def testViewInvite(self):
    self.data.createProfile()
    invitation = self.createInvitation()
    url = '/gsoc/invitation/%s/%s' % (self.gsoc.key().name(), invitation.key().id())
    response = self.client.get(url)
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/soc/request/base.html')

    postdata = {'action': 'Reject'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invitation = Request.all().get()
    self.assertEqual('rejected', invitation.status)

    # test that you can change after the fact
    postdata = {'action': 'Accept'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
Esempio n. 8
0
    def testRequestMentor(self):
        # test GET
        self.data.createProfile()
        url = '/gsoc/request/' + self.org.key().name()
        response = self.client.get(url)
        self.assertRequestTemplatesUsed(response)

        # test POST
        override = {
            'status': 'pending',
            'role': 'mentor',
            'type': 'Request',
            'user': self.data.user,
            'group': self.org
        }
        response, properties = self.modelPost(url, Request, override)

        request = Request.all().get()
        self.assertPropertiesEqual(properties, request)
Esempio n. 9
0
  def checkAccess(self):
    self.check.isProfileActive()
    
    id = int(self.data.kwargs['id'])
    self.data.invite = Request.get_by_id(id)
    self.check.isRequestPresent(self.data.invite, id)

    self.data.organization = self.data.invite.group
    self.data.invited_user = self.data.invite.user

    if self.data.POST:
      self.data.action = self.data.POST['action']

      if self.data.action == self.ACTIONS['accept']:
        self.check.canRespondToInvite()
      elif self.data.action == self.ACTIONS['reject']:
        self.check.canRespondToInvite()
    else:
      self.check.canViewInvite()

    self.mutator.canRespondForUser()
Esempio n. 10
0
  def testViewInvite(self):
    self.data.createProfile()
    invitation = self.createInvitation()
    url = '/gsoc/invitation/%s/%s' % (self.gsoc.key().name(), invitation.key().id())
    response = self.get(url)
    self.assertGSoCTemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/soc/request/base.html')

    postdata = {'action': 'Reject'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invitation = Request.all().get()
    self.assertEqual('rejected', invitation.status)

    # test that you can change after the fact
    postdata = {'action': 'Accept'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)

    profile = db.get(self.data.profile.key())
    self.assertEqual(1, profile.mentor_for.count(self.org.key()))
    self.assertTrue(profile.is_mentor)
    self.assertFalse(profile.is_student)
    self.assertFalse(profile.is_org_admin)
    self.assertFalse(profile.org_admin_for)

    # test admin invite
    invitation.status = 'pending'
    invitation.role = 'org_admin'
    invitation.put()

    response = self.post(url, postdata)
    self.assertResponseRedirect(response)

    profile = db.get(self.data.profile.key())
    self.assertEqual(1, profile.mentor_for.count(self.org.key()))
    self.assertEqual(1, profile.org_admin_for.count(self.org.key()))
    self.assertFalse(profile.is_student)
    self.assertTrue(profile.is_mentor)
    self.assertTrue(profile.is_org_admin)
Esempio n. 11
0
  def testInviteOrgAdmin(self):
    # test GET
    self.data.createOrgAdmin(self.org)
    url = '/gsoc/invite/org_admin/' + self.org.key().name()
    response = self.get(url)
    self.assertInviteTemplatesUsed(response)

    # create other user to send invite to
    other_data = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_data.createOtherUser('*****@*****.**')
    other_data.createProfile()
    other_data.notificationSettings(new_invites=True)
    other_user = other_data.user

    # test POST
    override = {
        'link_id': other_user.link_id, 'status': 'pending',
        'role': 'org_admin', 'user': other_user, 'org': self.org,
        'type': 'Invitation',
        # TODO(SRabbelier): add this as soon as we make User Request's parent
        # 'parent': other_user,
    }
    response, properties = self.modelPost(url, Request, override)
    self.assertEmailSent(to=other_data.profile.email, n=1)

    invitation = Request.all().get()
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)

    other_data2 = GSoCProfileHelper(self.gsoc, self.dev_test)
    other_data2.createOtherUser('*****@*****.**')
    other_data2.createProfile()
    other_data2.notificationSettings()

    invitation.delete()
    override['link_id'] = '[email protected], [email protected]'
    other_data.notificationSettings()
    response, properties = self.modelPost(url, Request, override)
    self.assertEmailSent(to=other_data.profile.email, n=1)

    invitations = Request.all().fetch(2)
    self.assertEqual(2, len(invitations))
    invitation = invitations[0]
    properties.pop('link_id')
    self.assertPropertiesEqual(properties, invitation)
    properties['user'] = other_data2.user
    self.assertPropertiesEqual(properties, invitations[1])

    # test withdraw/resubmit invite
    url = '/gsoc/invitation/%s/%s' % (self.gsoc.key().name(), invitation.key().id())

    other_data.notificationSettings(invite_handled=True)

    postdata = {'action': 'Withdraw'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invite = Request.all().get()
    self.assertEqual('withdrawn', invite.status)
    self.assertEmailSent(to=other_data.profile.email, n=2)

    # test that you can resubmit
    postdata = {'action': 'Resubmit'}
    response = self.post(url, postdata)
    self.assertResponseRedirect(response)
    invite = Request.all().get()
    self.assertEqual('pending', invite.status)
    self.assertEmailSent(to=other_data.profile.email, n=3)