Beispiel #1
0
def completeRequestForRole(role_entity, role_name):
  """Marks the request that leads to the given role_entity as completed.
  
  Args:
    role_entity: A datastore entity that is either a role or a subclass 
      of the role model
    role_name: The name in the request that is used to describe the 
      type of the role_entity
   
  """

  from soc.logic.models.request import logic as request_logic

  # create the query properties for the specific role
  properties = {'scope_path' : role_entity.scope_path,
      'link_id': role_entity.link_id,
      'role': role_name}

  # get the request that complies with properties
  request_entity = request_logic.getForFields(properties, unique=True)

  # mark the request completed, if there is any
  if request_entity:
    request_logic.updateEntityProperties(
        request_entity, {'status': 'completed'})
Beispiel #2
0
    def processRequest(self,
                       request,
                       access_type,
                       page_name=None,
                       params=None,
                       **kwargs):
        """Creates the page upon which a request can be processed.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        # get the request entity using the information from kwargs
        request_entity = request_logic.getFromIDOr404(int(kwargs['id']))

        # get the context for this webpage
        context = responses.getUniversalContext(request)
        responses.useJavaScript(context, params['js_uses_all'])

        context['page_name'] = '%s from %s to become a %s' % (
            page_name, request_entity.user.name, params['name'])

        # TODO(ljvderijk): Should be a POST request
        get_dict = request.GET

        if 'status' in get_dict.keys():
            if get_dict['status'] in [
                    'group_accepted', 'rejected', 'withdrawn', 'ignored'
            ]:
                # update the request_entity and redirect away from this page
                request_status = get_dict['status']

                # only update when the status is changing
                if request_status != request_entity.status:
                    request_logic.updateEntityProperties(
                        request_entity, {'status': get_dict['status']})

                group_view = params.get('group_view')
                if not group_view:
                    return http.HttpResponseRedirect('/')
                else:
                    # redirect to the requests list
                    return http.HttpResponseRedirect(
                        redirects.getListRequestsRedirect(
                            request_entity.group, group_view.getParams()))

        # put the entity in the context
        context['entity'] = request_entity
        context['request_status'] = request_entity.status
        context['role_verbose'] = params['name']
        context['url_name'] = params['url_name']

        #display the request processing page using the appropriate template
        template = request_view.view.getParams()['request_processing_template']

        return responses.respond(request, template, context=context)
Beispiel #3
0
  def processInvite(self, request, access_type,
                   page_name=None, params=None, **kwargs):
    """Creates the page upon which an invite can be processed.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    from soc.views.models.role import ROLE_VIEWS

    # get the context for this webpage
    context = responses.getUniversalContext(request)
    helper.responses.useJavaScript(context, params['js_uses_all'])

    # get the request entity using the information from kwargs
    request_entity = request_logic.getFromIDOr404(int(kwargs['id']))

    invite_accepted_redirect = redirects.getInviteAcceptedRedirect(
        request_entity, self._params)

    role_params = ROLE_VIEWS[request_entity.role].getParams()

    role_logic = role_params['logic']
    if not role_logic.canRejectInvite(request_entity.group):
      return http.HttpResponseRedirect(invite_accepted_redirect)

    # set the page name using the request_entity
    context['page_name'] = '%s %s for %s' % (page_name, 
        role_params['name'], request_entity.group.name)

    get_dict = request.GET

    # TODO(ljvderijk): Should be made a POST request.
    if 'status' in get_dict.keys():
      if get_dict['status'] == 'canceled':
        # this invite has been canceled mark as such
        request_logic.updateEntityProperties(request_entity, {
            'status': 'canceled'})

        # redirect to user request overview
        return http.HttpResponseRedirect('/user/requests')

    # put the entity in the context
    context['entity'] = request_entity
    context['module_name'] = params['module_name']
    context['role_name'] = role_params['name']
    context['invite_accepted_redirect'] = (invite_accepted_redirect)

    #display the invite processing page using the appropriate template
    template = params['invite_processing_template']

    return responses.respond(request, template, context=context)
Beispiel #4
0
  def processRequest(self, request, access_type,
                     page_name=None, params=None, **kwargs):
    """Creates the page upon which a request can be processed.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    # get the request entity using the information from kwargs
    request_entity = request_logic.getFromIDOr404(int(kwargs['id']))

    # get the context for this webpage
    context = responses.getUniversalContext(request)
    responses.useJavaScript(context, params['js_uses_all'])

    context['page_name'] = '%s from %s to become a %s' % (
        page_name, request_entity.user.name, params['name'])

    # TODO(ljvderijk): Should be a POST request
    get_dict = request.GET

    if 'status' in get_dict.keys():
      if get_dict['status'] in ['group_accepted', 'rejected', 'withdrawn',
                                'ignored']:
        # update the request_entity and redirect away from this page
        request_status = get_dict['status']

        # only update when the status is changing
        if request_status != request_entity.status:
          request_logic.updateEntityProperties(request_entity, {
              'status': get_dict['status']})

        group_view = params.get('group_view')
        if not group_view:
          return http.HttpResponseRedirect('/')
        else:
          # redirect to the requests list
          return http.HttpResponseRedirect(
              redirects.getListRequestsRedirect(request_entity.group,
                  group_view.getParams()))

    # put the entity in the context
    context['entity'] = request_entity
    context['request_status'] = request_entity.status 
    context['role_verbose'] = params['name']
    context['url_name'] = params['url_name']

    #display the request processing page using the appropriate template
    template = request_view.view.getParams()['request_processing_template']

    return responses.respond(request, template, context=context)
Beispiel #5
0
    def processInvite(self,
                      request,
                      access_type,
                      page_name=None,
                      params=None,
                      **kwargs):
        """Creates the page upon which an invite can be processed.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        from soc.views.models.role import ROLE_VIEWS

        # get the context for this webpage
        context = responses.getUniversalContext(request)
        helper.responses.useJavaScript(context, params['js_uses_all'])

        # get the request entity using the information from kwargs
        request_entity = request_logic.getFromIDOr404(int(kwargs['id']))

        role_params = ROLE_VIEWS[request_entity.role].getParams()

        # set the page name using the request_entity
        context['page_name'] = '%s %s for %s' % (
            page_name, role_params['name'], request_entity.group.name)

        get_dict = request.GET

        if 'status' in get_dict.keys():
            if get_dict['status'] == 'rejected':
                # this invite has been rejected mark as rejected
                request_logic.updateEntityProperties(request_entity,
                                                     {'status': 'rejected'})

                # redirect to user request overview
                return http.HttpResponseRedirect('/user/requests')

        # put the entity in the context
        context['entity'] = request_entity
        context['module_name'] = params['module_name']
        context['role_name'] = role_params['name']
        context['invite_accepted_redirect'] = (
            redirects.getInviteAcceptedRedirect(request_entity, self._params))

        #display the invite processing page using the appropriate template
        template = params['invite_processing_template']

        return responses.respond(request, template, context=context)
Beispiel #6
0
    def acceptInvitePost(self, request, context, params, request_entity,
                         **kwargs):
        """Handles the POST request concerning the creation of a Role via an
    invite.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      request_entity: Request that is being accepted
      kwargs: contains the ID for the Request entity
    """

        # populate the form using the POST data
        form = params['invited_create_form'](request.POST)

        if not form.is_valid():
            # return the invalid form response
            return self._constructResponse(request,
                                           entity=None,
                                           context=context,
                                           form=form,
                                           params=params)

        # collect the cleaned data from the valid form
        key_name, fields = soc.views.helper.forms.collectCleanedFields(form)

        # set the user and link_id fields to the right property
        fields['user'] = request_entity.user
        fields['link_id'] = request_entity.user.link_id
        fields['scope'] = request_entity.group
        fields['scope_path'] = request_entity.group.key().id_or_name()
        # make sure that this role becomes active once more in case this user
        # has been reinvited
        fields['status'] = 'active'

        # call the post process method
        self._acceptInvitePost(fields, request, context, params, **kwargs)

        # get the key_name for the new entity
        key_name = self._logic.getKeyNameFromFields(fields)

        # create new Role entity
        _ = self._logic.updateOrCreateFromKeyName(fields, key_name)

        # mark the request as completed
        request_fields = {'status': 'completed'}
        request_logic.updateEntityProperties(request_entity, request_fields)

        # redirect to the roles overview page
        return http.HttpResponseRedirect('/user/roles')
Beispiel #7
0
  def acceptInvitePost(self, request, context, params, 
                       request_entity, **kwargs):
    """Handles the POST request concerning the creation of a Role via an
    invite.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      request_entity: Request that is being accepted
      kwargs: contains the ID for the Request entity
    """

    # populate the form using the POST data
    form = params['invited_create_form'](request.POST)

    if not form.is_valid():
      # return the invalid form response
      return self._constructResponse(request, entity=None, context=context,
          form=form, params=params)

    # collect the cleaned data from the valid form
    key_name, fields = soc.views.helper.forms.collectCleanedFields(form)

    # set the user and link_id fields to the right property
    fields['user'] = request_entity.user
    fields['link_id'] = request_entity.user.link_id
    fields['scope'] = request_entity.group
    fields['scope_path'] = request_entity.group.key().id_or_name()
    # make sure that this role becomes active once more in case this user
    # has been reinvited
    fields ['status'] = 'active'

    # call the post process method
    self._acceptInvitePost(fields, request, context, params, **kwargs)

    # get the key_name for the new entity
    key_name = self._logic.getKeyNameFromFields(fields)

    # create new Role entity
    _ = self._logic.updateOrCreateFromKeyName(fields, key_name)

    # mark the request as completed
    request_fields = {'status': 'completed'}
    request_logic.updateEntityProperties(request_entity, request_fields)

    # redirect to the roles overview page
    return http.HttpResponseRedirect('/user/roles')