Exemplo n.º 1
0
def sendRequestTaskNotification(org_admins, message):
  """Sends notifications to org admins that there is a student who requested
  more tasks from them.

  Args:
    org_admins: a list of org admins who the notification should be sent to
    message: a short message that will be included to the notification
  """

  from soc.logic.models.site import logic as site_logic

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, abort
    return
  else:
    (sender_name, sender) = default_sender

  # get site name
  site_entity = site_logic.getSingleton()
  template = DEF_TASK_REQUEST_TEMPLATE

  properties = {
      'message': message,
      'sender_name': sender_name,
      }

  for org_admin in org_admins:
    to = org_admin.user
    properties['to'] = to
    properties['to_name'] = to.name

    notifications.sendNotification(to, None, properties, subject, template)
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
0
def sendBulkCreationCompleted(bulk_data):
  """Sends out a notification that the bulk creation of tasks has been
  completed.

  Any error messages that have been generated are also added to the notification.

  Args:
    bulk_data: GCIBulkCreateData entity containing information needed to
               populate the notification.
  """
  message_properties = {
      'bulk_data' : bulk_data
      }

  subject = DEF_BULK_CREATE_COMPLETE_SUBJECT_MSG
  template = DEF_BULK_CREATE_COMPLETE_TEMPLATE

  notifications.sendNotification(
      bulk_data.created_by.user, None, message_properties, subject, template)