Ejemplo n.º 1
0
 def get(self, club_id, email_id):
     # check credentials
     if not(check_admin(club_id)):
         add_notify("Error", "You do not have the appropriate permissions")
         self.redirect("/")
         return
     user = users.get_current_user()
     club = Club.get_by_key_name(club_id)
     
     # get the email to be admin-ified
     email = Email.get_by_key_name(email_id)
     if not(email):
         add_notify("Error", "No email to be promoted!")
         self.redirect("/club/%s" % club.slug)
         return
     # find the link to promote it
     query = EmailToClub.all()
     query.filter("email =", email)
     query.filter("club =", club)
     link = query.get()
     if not(link):
         add_notify("Error", "No email to be promoted!")
         self.redirect("/club/%s" % club.slug)
         return
     if not link.enable:
         add_notify("Error", "Can't promote a disabled email")
         self.redirect("/club/%s" % club.slug)
         return
     # flip the admin bit
     link.admin = not(link.admin)
     link.put()
     # make sure we have at least one admin
     query = EmailToClub.all()
     query.filter("club =", club)
     query.filter("admin =", True)
     admin_check = query.get()
     if not(admin_check):
         # reverse the admin
         link.admin = True
         link.put()
     # send an email if you've just been promoted
     if link.admin:
         domain = "http://%s.appspot.com" % get_application_id()
         msg = mail.EmailMessage()
         fromaddr = "noreply@%s.appspotmail.com" % get_application_id()
         msg.sender  = "Flyer Guy <%s>" % fromaddr
         msg.to      = email.email
         msg.subject = "[Flyer] You've an admin of %s!" % club.name
         msg.html    = template.render("templates/email_admin.html",
                                       {"domain":domain,
                                        "club":club.name,
                                        "email":email.id})
         try:
             msg.send()
         except apiproxy_errors.OverQuotaError, (message,):
             # Log the error
             add_notify("Error", "Could not send email")
             logging.error("Could not send email")
             logging.error(message)
Ejemplo n.º 2
0
    def get(self, club_id, email_id):
        # check credentials
        if not(check_admin(club_id)):
            add_notify("Error", "You do not have the appropriate permissions")
            self.redirect("/")
            return
        club = Club.get_by_key_name(club_id)

        # get the email link to be deleted
        email = Email.get_by_key_name(email_id)
        if not(email):
            add_notify("Error", "No email to be deleted!")
            self.redirect("/club/%s" % club.slug)
            return
        # find the link
        query = EmailToClub.all()
        query.filter("email =", email)
        query.filter("club =", club)
        link = query.get()
        if not(link):
            add_notify("Error", "No email to be deleted!")
            self.redirect("/club/%s" % club.slug)
            return
        # make sure it's not the last admin
        query = EmailToClub.all()
        query.filter("club =", club)
        admins = query.fetch(2)
        if len(admins) < 2 and link.admin:
            add_notify("Error", "Will not delete the last club admin")
            self.redirect("/club/%s" % club.slug)
            return
        # delete the link
        link.delete()
        # hail our success
        add_notify("Notice", "Email deleted")
        self.redirect("/club/%s" % club.slug)