コード例 #1
0
ファイル: invite.py プロジェクト: adviti/melange
  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)
コード例 #2
0
ファイル: request.py プロジェクト: SRabbelier/Melange
  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)
コード例 #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)
コード例 #4
0
ファイル: request.py プロジェクト: adviti/melange
    def checkAccess(self):
        self.check.isProfileActive()

        request_id = int(self.data.kwargs["id"])
        self.data.invite = self.data.request_entity = GSoCRequest.get_by_id(request_id)
        self.check.isRequestPresent(request_id)

        self.data.organization = self.data.request_entity.org
        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)
コード例 #5
0
ファイル: proposal_review.py プロジェクト: SRabbelier/Melange
  def checkAccess(self):
    self.data.proposer_user = User.get_by_key_name(self.data.kwargs['student'])

    fields = ['sponsor', 'program', 'student']
    key_name = '/'.join(self.data.kwargs[i] for i in fields)

    self.data.proposer_profile = GSoCProfile.get_by_key_name(
        key_name, parent=self.data.proposer_user)

    if not self.data.proposer_profile:
      raise NotFound('Requested user does not exist')

    self.data.proposal = GSoCProposal.get_by_id(
        int(self.data.kwargs['id']),
        parent=self.data.proposer_profile)

    if not self.data.proposal:
      raise NotFound('Requested proposal does not exist')

    self.data.proposal_org = self.data.proposal.org

    self.check.canAccessProposalEntity()
    self.mutator.commentVisible()
コード例 #6
0
    def checkAccess(self):
        self.data.proposer_user = User.get_by_key_name(
            self.data.kwargs['student'])

        fields = ['sponsor', 'program', 'student']
        key_name = '/'.join(self.data.kwargs[i] for i in fields)

        self.data.proposer_profile = GSoCProfile.get_by_key_name(
            key_name, parent=self.data.proposer_user)

        if not self.data.proposer_profile:
            raise NotFound('Requested user does not exist')

        self.data.proposal = GSoCProposal.get_by_id(
            int(self.data.kwargs['id']), parent=self.data.proposer_profile)

        if not self.data.proposal:
            raise NotFound('Requested proposal does not exist')

        self.data.proposal_org = self.data.proposal.org

        self.check.canAccessProposalEntity()
        self.mutator.commentVisible()
コード例 #7
0
ファイル: invite.py プロジェクト: pombredanne/Melange-1
    
    # check if the organization has already sent an invitation to the user
    query = db.Query(Request)
    query.filter('type', 'Invitation')
    query.filter('user', invited_user)
    query.filter('role', self.request_data.kwargs['role'])
    query.filter('group', self.request_data.organization)
    if query.get():
      raise djangoforms.ValidationError(
          'An invitation to this user has already been sent.')

    # check if the user that is invited does not have the role
    key_name = '/'.join([
        self.request_data.program.key().name(),
        invited_user.link_id])
    profile = GSoCProfile.get_by_key_name(key_name, parent=invited_user)

    if not profile:
      msg = ("The specified user has a User account (the link_id is valid), "
             "but they do not yet have a profile for this %s. "
             "You cannot invite them until they create a profile.")
      raise djangoforms.ValidationError(msg % self.request_data.program.name)

    if self.request_data.kwargs['role'] == 'org_admin':
      role_for = profile.org_admin_for
    else:
      role_for = profile.mentor_for

    for key in role_for:
      if key == self.request_data.organization.key():
        raise djangoforms.ValidationError(
コード例 #8
0
ファイル: invite.py プロジェクト: adviti/melange
    
    # check if the organization has already sent an invitation to the user
    query = db.Query(Request)
    query.filter('type', 'Invitation')
    query.filter('user', invited_user)
    query.filter('role', self.request_data.kwargs['role'])
    query.filter('org', self.request_data.organization)
    if query.get():
      raise djangoforms.ValidationError(
          'An invitation to this user has already been sent.')

    # check if the user that is invited does not have the role
    key_name = '/'.join([
        self.request_data.program.key().name(),
        invited_user.link_id])
    profile = self.request_data.invite_profile = GSoCProfile.get_by_key_name(
        key_name, parent=invited_user)

    if not profile:
      msg = ('The specified user has a User account (the link_id is valid), '
             'but they do not yet have a profile for this %s. '
             'You cannot invite them until they create a profile.')
      raise djangoforms.ValidationError(msg % self.request_data.program.name)

    if profile.student_info:
      raise djangoforms.ValidationError('That user is a student')

    if self.request_data.kwargs['role'] == 'org_admin':
      role_for = profile.org_admin_for
    else:
      role_for = set(profile.org_admin_for + profile.mentor_for)
コード例 #9
0
ファイル: request_data.py プロジェクト: adviti/melange
  def populate(self, redirect, request, args, kwargs):
    """Populates the fields in the RequestData object.

    Args:
      request: Django HTTPRequest object.
      args & kwargs: The args and kwargs django sends along.
    """
    super(RequestData, self).populate(redirect, request, args, kwargs)

    if kwargs.get('sponsor') and kwargs.get('program'):
      program_key_name = "%s/%s" % (kwargs['sponsor'], kwargs['program'])
      program_key = db.Key.from_path('GSoCProgram', program_key_name)
    else:
      from soc.models.site import Site
      program_key = Site.active_program.get_value_for_datastore(self.site)
      program_key_name = program_key.name()
      import logging
      logging.error("No program specified")

    timeline_key = db.Key.from_path('GSoCTimeline', program_key_name)

    org_app_key_name = 'gsoc_program/%s/orgapp' % program_key_name
    org_app_key = db.Key.from_path('OrgAppSurvey', org_app_key_name)

    keys = [program_key, timeline_key, org_app_key]

    self.program, self.program_timeline, self.org_app = db.get(keys)

    if not self.program:
      raise NotFound("There is no program for url '%s'" % program_key_name)

    self.timeline = TimelineHelper(self.program_timeline, self.org_app)

    if kwargs.get('organization'):
      fields = [self.program.key().id_or_name(), kwargs.get('organization')]
      org_key_name = '/'.join(fields)
      self.organization = GSoCOrganization.get_by_key_name(org_key_name)
      if not self.organization:
        raise NotFound("There is no organization for url '%s'" % org_key_name)

    if self.user:
      key_name = '%s/%s' % (self.program.key().name(), self.user.link_id)
      self.profile = GSoCProfile.get_by_key_name(
          key_name, parent=self.user)

      from soc.modules.gsoc.models.program import GSoCProgram
      host_key = GSoCProgram.scope.get_value_for_datastore(self.program)
      self.is_host = host_key in self.user.host_for

    if self.profile:
      org_keys = set(self.profile.mentor_for + self.profile.org_admin_for)

      prop = GSoCProfile.student_info
      student_info_key = prop.get_value_for_datastore(self.profile)

      if student_info_key:
        self.student_info = db.get(student_info_key)
        self.is_student = True
      else:
        orgs = db.get(org_keys)

        org_map = self.org_map = dict((i.key(), i) for i in orgs)

        self.mentor_for = org_map.values()
        self.org_admin_for = [org_map[i] for i in self.profile.org_admin_for]

    self.is_org_admin = self.is_host or bool(self.org_admin_for)
    self.is_mentor = self.is_org_admin or bool(self.mentor_for)