Beispiel #1
0
class TeamService:
    """
  Service Layer for all the teams
  """
    def __init__(self):
        self.store = TeamStore()

    def get_team_info(self, team_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.get_team_info(team_id)
        if err:
            return None, err
        return serialize(team)

    def list_teams(self, team_id) -> (list, MassEnergizeAPIError):
        team, err = self.store.list_teams(team_id)
        if err:
            return None, err
        return serialize(team), None

    def create_team(self, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.create_team(args)
        if err:
            return None, err
        return serialize(team), None

    def update_team(self, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.update_team(args)
        if err:
            return None, err
        return serialize(team), None

    def delete_team(self, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.delete_team(args)
        if err:
            return None, err
        return serialize(team), None

    def list_teams_for_community_admin(
            self, community_id) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_community_admin(community_id)
        if err:
            return None, err
        return serialize_all(teams), None

    def list_teams_for_super_admin(self) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_super_admin()
        if err:
            return None, err
        return serialize_all(teams), None
Beispiel #2
0
 def __init__(self):
     self.store = TeamStore()
Beispiel #3
0
class TeamService:
    """
  Service Layer for all the teams
  """
    def __init__(self):
        self.store = TeamStore()
        self.message_store = MessageStore()

    def get_team_info(self, team_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.get_team_info(team_id)
        if err:
            return None, err
        return serialize(team, full=True), None

    def list_teams(self, context: Context,
                   args) -> (list, MassEnergizeAPIError):
        team, err = self.store.list_teams(context, args)
        if err:
            return None, err
        return serialize_all(team), None

    def team_stats(self, context: Context,
                   args) -> (list, MassEnergizeAPIError):
        stats, err = self.store.team_stats(context, args)
        if err:
            return None, err
        return stats, None

    def create_team(self, user_id, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.create_team(user_id, args)
        if err:
            return None, err
        return serialize(team), None

    def update_team(self, team_id, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.update_team(team_id, args)
        if err:
            return None, err
        return serialize(team), None

    def delete_team(self, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.delete_team(args)
        if err:
            return None, err
        return serialize(team), None

    def join_team(self, team_id, user_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.join_team(team_id, user_id)
        if err:
            return None, err
        return serialize(team), None

    def leave_team(self, team_id, user_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.leave_team(team_id, user_id)
        if err:
            return None, err
        return serialize(team), None

    def add_member(self, context, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.add_team_member(context, args)
        if err:
            return None, err
        return serialize(team), None

    def remove_team_member(self, context,
                           args) -> (dict, MassEnergizeAPIError):
        res, err = self.store.remove_team_member(context, args)
        if err:
            return None, err
        return res, None

    def members(self, context, args) -> (dict, MassEnergizeAPIError):
        members, err = self.store.members(context, args)
        if err:
            return None, err
        return serialize_all(members), None

    def message_admin(self, context, args) -> (dict, MassEnergizeAPIError):
        message_info, err = self.message_store.message_team_admin(
            context, args)
        if err:
            return None, err
        return serialize(message_info), None

    def list_teams_for_community_admin(self, context: Context,
                                       args) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_community_admin(context, args)
        if err:
            return None, err
        return serialize_all(teams), None

    def list_teams_for_super_admin(
            self, context: Context) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_super_admin(context)
        if err:
            return None, err
        return serialize_all(teams), None
Beispiel #4
0
 def __init__(self):
     self.store = TeamStore()
     self.message_store = MessageStore()
Beispiel #5
0
class MessageService:
    """
  Service Layer for all the messages
  """
    def __init__(self):
        self.store = MessageStore()
        self.team_store = TeamStore()

    def get_message_info(self, context,
                         message_id) -> (dict, MassEnergizeAPIError):
        message, err = self.store.get_message_info(context, message_id)
        if err:
            return None, err
        return serialize(message, full=True), None

    def reply_from_community_admin(self, context,
                                   args) -> (list, MassEnergizeAPIError):
        message, err = self.store.get_message_info(context, args)
        if err:
            return None, err
        title = args.pop('title', None)
        to = args.pop('to', None)
        body = args.pop('body', None)
        success = send_massenergize_email(title, body, to)
        if success:
            message.have_replied = True
            message.save()
        # attached_file = args.pop('attached_file', None)
        return success, None

    def forward_to_team_admins(self, context: Context,
                               args) -> (list, MassEnergizeAPIError):
        message, err = self.store.get_message_info(context, args)
        if err:
            return None, err

        team_id = message.team.pk if message.team else None
        team_admins, err = self.team_store.get_team_admins(context, team_id)

        if (err):
            return None, err

        sender_name = message.user_name or (message.user
                                            and message.user.full_name)
        sender_email = message.email or (message.user and message.user.email)
        raw_msg = message.body
        title = f"FW: {message.title}"

        body = f"\n\
    Hi Team Leader,\n\
    I am forwarding a message for you you from our MassEnergize community portal.\n\
    Your friendly Community Admin.\n\n\
    Sender: {sender_name}\n\
    Sender's email: {sender_email}\n\
    Sender's message: \n\
    {raw_msg}\
    "

        for admin in team_admins:
            to = admin.email
            if not to:
                continue

            success = send_massenergize_email(title, body, to)
            if success:
                message.have_forwarded = True
                message.save()

        # attached_file = args.pop('attached_file', None)

        return True, None

    def delete_message(self, message_id) -> (dict, MassEnergizeAPIError):
        message, err = self.store.delete_message(message_id)
        if err:
            return None, err
        return serialize(message), None

    def list_community_admin_messages_for_community_admin(
            self, context: Context, args) -> (list, MassEnergizeAPIError):
        messages, err = self.store.list_community_admin_messages(context, args)
        if err:
            return None, err
        return serialize_all(messages), None

    def list_team_admin_messages_for_community_admin(
            self, context: Context) -> (list, MassEnergizeAPIError):
        messages, err = self.store.list_team_admin_messages(context)
        if err:
            return None, err
        return serialize_all(messages), None
Beispiel #6
0
class MessageService:
  """
  Service Layer for all the messages
  """

  def __init__(self):
    self.store =  MessageStore()
    self.team_store = TeamStore()

  def get_message_info(self, context, message_id) -> (dict, MassEnergizeAPIError):
    message, err = self.store.get_message_info(context, message_id)
    if err:
      return None, err
    return serialize(message, full=True), None

  def reply_from_community_admin(self, context, args) -> (list, MassEnergizeAPIError):
    message, err = self.store.get_message_info(context, args)
    if err:
      return None, err
    title = args.pop('title', None)
    to = args.pop('to', None)
    body = args.pop('body', None)
    success = send_massenergize_email(title, body, to)
    if success:
      message.have_replied = True
      message.save()
    # attached_file = args.pop('attached_file', None)    
    return success, None

  def reply_from_team_admin(self, context, args) -> (list, MassEnergizeAPIError):
    message, err = self.store.get_message_info(context, args)
    if err:
      return None, err
    team_id = message.team.pk if message.team else None
    team_admins = self.team_store.get_team_admins(context, team_id)
    title = args.pop('title', None)
    body = args.pop('body', None)
    for admin in team_admins:
      to = admin.email
      if not to:
        continue
      success = send_massenergize_email(title, body, to)
      if success:
        message.have_forwarded = True
        message.save()
    # attached_file = args.pop('attached_file', None)    

    return True, None


  def delete_message(self, message_id) -> (dict, MassEnergizeAPIError):
    message, err = self.store.delete_message(message_id)
    if err:
      return None, err
    return serialize(message), None


  def list_community_admin_messages_for_community_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
    messages, err = self.store.list_community_admin_messages(context, args)
    if err:
      return None, err
    return serialize_all(messages), None


  def list_team_admin_messages_for_super_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
    messages, err = self.store.list_team_admin_messages(context, args)
    if err:
      return None, err
    return serialize_all(messages), None
Beispiel #7
0
class TeamService:
    """
  Service Layer for all the teams
  """
    def __init__(self):
        self.store = TeamStore()
        self.message_store = MessageStore()

    def get_team_info(self, context: Context,
                      team_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.get_team_info(context, team_id)
        if err:
            return None, err
        return serialize(team, full=True), None

    def list_teams(self, context: Context,
                   args) -> (list, MassEnergizeAPIError):
        team, err = self.store.list_teams(context, args)
        if err:
            return None, err
        return serialize_all(team), None

    def team_stats(self, context: Context,
                   args) -> (list, MassEnergizeAPIError):
        stats, err = self.store.team_stats(context, args)
        if err:
            return None, err
        return stats, None

    def create_team(self, context, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.create_team(context, args)
        if err:
            return None, err

        # within store.create_team, an e-mail was sent to the community admin
        #
        # TODO: the following functionality is needed
        # message to the effect that you have been named as a team admin
        #message_info, err = self.message_store.message_team_admin(context, args)
        #
        # message to community admins that a team was created (needs to be recorded in admin portal because the e-mail may be lost)
        #message_info, err = self.message_store.message_admin(context, args)

        return serialize(team), None

    def update_team(self, team_id, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.update_team(team_id, args)
        if err:
            return None, err
        return serialize(team), None

    def delete_team(self, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.delete_team(args)
        if err:
            return None, err
        return serialize(team), None

    def join_team(self, team_id, user_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.join_team(team_id, user_id)
        if err:
            return None, err
        return serialize(team), None

    def leave_team(self, team_id, user_id) -> (dict, MassEnergizeAPIError):
        team, err = self.store.leave_team(team_id, user_id)
        if err:
            return None, err
        return serialize(team), None

    def add_member(self, context, args) -> (dict, MassEnergizeAPIError):
        team, err = self.store.add_team_member(context, args)
        if err:
            return None, err
        return serialize(team), None

    def remove_team_member(self, context,
                           args) -> (dict, MassEnergizeAPIError):
        res, err = self.store.remove_team_member(context, args)
        if err:
            return None, err
        return res, None

    def members(self, context, args) -> (dict, MassEnergizeAPIError):
        members, err = self.store.members(context, args)
        if err:
            return None, err
        return serialize_all(members), None

    def members_preferred_names(self, context,
                                args) -> (dict, MassEnergizeAPIError):
        preferred_names, err = self.store.members_preferred_names(
            context, args)
        if err:
            return None, err
        return preferred_names, None

    def message_admin(self, context, args) -> (dict, MassEnergizeAPIError):
        message_info, err = self.message_store.message_team_admin(
            context, args)
        if err:
            return None, err
        return serialize(message_info), None

    def list_teams_for_community_admin(self, context: Context,
                                       args) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_community_admin(context, args)
        if err:
            return None, err
        return serialize_all(teams), None

    def list_teams_for_super_admin(
            self, context: Context) -> (list, MassEnergizeAPIError):
        teams, err = self.store.list_teams_for_super_admin(context)
        if err:
            return None, err
        return serialize_all(teams), None