def approve_booking(self, user, booking_id): booking = Booking.get(booking_id) if not booking: return {"error": "No such booking"} if str(booking.user.key()) == str(user.key()): booking.approved_by_customer = True booking.put() return model_to_dict(booking) if business.user_owns_business(user.user_id(), booking.business_id): booking.approved_by_contractor = True booking.put() return model_to_dict(booking) return {"error": "Insufficient permissions"}
def send_message_code(user, business_id, message, user_id): recv_user = None if user_id: if not business.user_owns_business(user.user_id(), business_id): return {"error": "You don't own that business"} recv_user = CoUser.get(user_id) if not recv_user: return {"error": "no such user"} interaction = InteractionRecord.gql("WHERE business_id = :1 AND user = :2", business_id, recv_user).get() if not interaction: return {"error": "no reason to talk to that person"} contractor = True else: interaction = InteractionRecord.guaranteed_get(business_id, user) contractor = False senderoo = Solicitation( interaction = interaction, from_contractor = contractor, when = js_time(), message = message ) senderoo.put() send_emails.message_recieved(user, business_id,recv_user, message) return model_to_dict(senderoo)
def get_clients(self, user, business_id): # This is the fun one # Going to need some caching user_id = user.user_id() if not user or not business.user_owns_business(user.user_id(), business_id): return {"error": "not allowed"} the_real_deal = InteractionRecord.gql("WHERE business_id = :1", business_id) ret = [] # This is so that all of the user's data comes through for i in the_real_deal: ret.append(model_to_dict(i.user)) return ret
def respond(self, user, business_id, user_to, message): """ Used by businesses to respond to user queries """ if not business.user_owns_business(user.user_id(), business_id): return {"error": "NOT ALLOWED DOG"} interaction = InteractionRecord.get(business_id, user_to) if not interaction: return {"error": "You cannot contact that user"} senderoo = Solicitation( interaction = interaction, from_contractor=True, when = js_time(), message = message ) senderoo.put() # TODO: tell everyone again return model_to_dict(senderoo)
def add_booking(self, user, business_id, start, end, user_with=None): if end < start: return {"error": "what are you doing? You can't end before you start"} new_booking = self.add_booking_code(user, business_id, start, end, user_with) return model_to_dict(new_booking)