Beispiel #1
0
def sendNewRequestNotification(request_entity):
  """Sends out a notification to the persons who can process this Request.

  Args:
    request_entity: an instance of Request model
  """

  from soc.logic.helper import notifications
  from soc.logic.models.role import ROLE_LOGICS
  from soc.views.models.role import ROLE_VIEWS

  # get the users who should get the notification
  to_users = []

  # retrieve the Role Logics which we should query on
  role_logic = ROLE_LOGICS[request_entity.role]
  role_logics_to_notify = role_logic.getRoleLogicsToNotifyUponNewRequest()

  # the scope of the roles is the same as the scope of the Request entity
  fields = {'scope': request_entity.group,
            'status': 'active'}

  for role_logic in role_logics_to_notify:
    roles = role_logic.getForFields(fields)

    for role_entity in roles:
      # TODO: this might lead to double notifications
      to_users.append(role_entity.user)

  # get the user the request is from
  user_entity = request_entity.user

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

  request_url = 'http://%(host)s%(redirect)s' % {
      'host': system.getHostname(),
      'redirect': redirects.getProcessRequestRedirect(request_entity, None),
      }

  message_properties = {
      'requester': user_entity.name,
      'role_verbose': role_params['name'],
      'group': request_entity.group.name,
      'request_url': request_url
      }

  subject = DEF_NEW_REQUEST_MSG_FMT % {
      'requester': user_entity.name,
      'role_verbose' : role_params['name'],
      'group' : request_entity.group.name
      }

  template = DEF_NEW_REQUEST_NOTIFICATION_TEMPLATE

  for to_user in to_users:
    notifications.sendNotification(to_user, None, message_properties,
                                   subject, template)
Beispiel #2
0
    def listRequests(self,
                     request,
                     access_type,
                     page_name=None,
                     params=None,
                     **kwargs):
        """Gives an overview of all the requests for a specific group.

    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
    """

        # set the pagename to include the link_id
        page_name = '%s %s' % (page_name, kwargs['link_id'])

        # get the group from the request
        group_logic = params['logic']

        group_entity = group_logic.getFromKeyFields(kwargs)

        role_names = params['role_views'].keys()

        # list all incoming requests
        filter = {
            'group': group_entity,
            'role': role_names,
            'status': ['new', 'group_accepted', 'ignored']
        }

        # create the list parameters
        req_params = request_view.getParams()

        # define the list redirect action to the request processing page
        req_params['public_row_extra'] = lambda entity: {
            'link': redirects.getProcessRequestRedirect(entity, None)
        }
        req_params['public_field_ignore'] = ['for']
        req_params['list_description'] = ugettext(
            "An overview of the %(name)s's invites and requests." % params)

        return self.list(request,
                         access_type='allow',
                         page_name=page_name,
                         params=req_params,
                         filter=filter,
                         **kwargs)
Beispiel #3
0
def sendNewRequestNotification(request_entity):
  """Sends out a notification to the persons who can process this Request.

  Args:
    request_entity: an instance of Request model
  """

  from soc.logic.helper import notifications
  from soc.logic.models.role import ROLE_LOGICS
  from soc.logic.models.user import logic as user_logic

  # get the users who should get the notification
  to_users = []

  # retrieve the Role Logics which we should query on
  role_logic = ROLE_LOGICS[request_entity.role]
  role_logics_to_notify = role_logic.getRoleLogicsToNotifyUponNewRequest()

  # the scope of the roles is the same as the scope of the Request entity
  fields = {'scope': request_entity.scope,
            'status': 'active'}

  for role_logic in role_logics_to_notify:
    roles = role_logic.getForFields(fields)

    for role_entity in roles:
      # TODO: this might lead to double notifications
      to_users.append(role_entity.user)

  # get the user the request is from
  properties = {'link_id': request_entity.link_id }
  user_entity = user_logic.getForFields(properties, unique=True)

  message_properties = {
      'requester_name': user_entity.name,
      'entity': request_entity,
      'request_url': redirects.getProcessRequestRedirect(request_entity, None)}

  subject = DEF_NEW_REQUEST_MSG_FMT % {
      'requester': user_entity.name,
      'role_verbose' : request_entity.role_verbose,
      'group' : request_entity.scope.name
      }

  template = DEF_NEW_REQUEST_NOTIFICATION_TEMPLATE

  for to_user in to_users:
    notifications.sendNotification(to_user, None, message_properties,
                                   subject, template)
Beispiel #4
0
  def listRequests(self, request, access_type,
                   page_name=None, params=None, **kwargs):
    """Gives an overview of all the requests for a specific group.

    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
    """

    # set the pagename to include the link_id
    page_name = '%s %s' % (page_name, kwargs['link_id'])

    # get the group from the request
    group_logic = params['logic']

    group_entity = group_logic.getFromKeyFields(kwargs)

    role_names = params['role_views'].keys()

    # list all incoming requests
    filter = {
        'group': group_entity,
        'role': role_names,
        'status': ['new', 'group_accepted', 'ignored']
        }

    # create the list parameters
    req_params = request_view.getParams()

    # define the list redirect action to the request processing page
    req_params['public_row_extra'] = lambda entity: {
        'link': redirects.getProcessRequestRedirect(entity, None)
    }
    req_params['public_field_ignore'] = ['for']
    req_params['list_description'] = ugettext(
        "An overview of the %(name)s's invites and requests." % params)

    return self.list(request, access_type='allow', page_name=page_name,
                     params=req_params, filter=filter, **kwargs)