def update_service(self, service_id, optional_params): if not self._user.is_authenticated or not self._user.can_edit(): self._log_warn("User not authorised to update services") return UNAUTHORISED service = self._get_updated_service_from_params( service_id, optional_params) self._service_dao.update(service) self._log_info("service updated " + str(service['id'])) return redirect_url('services_api')
def add_service(self, optional_params): if not self._user.is_authenticated or not self._user.can_edit(): self._log_warn("User not authorised to add services") return UNAUTHORISED service = ServiceController._get_updated_service_from_params( None, optional_params) self._service_dao.set(service) self._log_info("service added " + str(service['id'])) return redirect_url('services_api')
def update_song(self, song_name, old_song_name, files): if not self._user.is_authenticated or not self._user.can_edit(): self._log_warn("user is not authorised to update song") return UNAUTHORISED if old_song_name != song_name: raise Exception("Currently unable to rename songs") update_data = SongController.get_song_creation_data(song_name, files) self._songs_dao.update(song_name, update_data) self._log_info("song updated for " + song_name) return redirect_url('song_api', user=self._user, name=song_name)
def add_song(self, song_name, ccli, files): if not self._user.is_authenticated or not self._user.can_edit(): self._log_warn("user is not authorised to add song") return UNAUTHORISED song = {'name': song_name, 'file_ids': {}, 'ccli': ccli, 'notes': ''} song_creation_data = SongController.get_song_creation_data( song_name, files) self._songs_dao.set(song, song_creation_data) self._log_info("new song added for " + song_name) return redirect_url('songs_api')
def add_new(self, request): if not self._user.is_authenticated or not self._user.can_email(): self._log_warn("Unauthorised user attempting to add new recipient") return UNAUTHORISED name = request['name'] email = request['email'] self._recipients_dao.set_recipient(email, name, 'test' in request, 'ppt' in request, 'service' in request) self._log_info("New recipient added: " + email) return redirect_url('recipients_api')
def update_user(self, id, scope): if not self._user.is_authenticated or not self._user.is_admin(): self._log_warn("User unauthorised to update users for " + self._user.email) return UNAUTHORISED if scope == 'field-marshal': scope = 'rdm/admin' elif scope == 'captain': scope = 'rdm/captain' elif scope == 'sergeant': scope = 'rdm/sergeant' elif scope == 'private': scope = 'rdm/private' self._user_dao.update_scope(id, scope) self._log_info("User " + str(id) + " updated to scope " + scope) return redirect_url('users_edit_page_api')
def update_slides(self, song_name, lyrics): if not self._user.is_authenticated or not self._user.can_edit(): self._log_warn("user is not authorised to update slides") return UNAUTHORISED file_name = song_name + " (slides).txt" file_path = "bin/" + song_name # TODO fix path out_f = open(file_path, "w") out_f.write(lyrics) out_f.close() upload_data = { 'file_type': 'txt', 'file_path': file_path, 'file_name': file_name } creation_data = {'slides': upload_data} self._songs_dao.update(song_name, creation_data) self._log_info("slides updated for " + song_name) return redirect_url('song_api', name=song_name)
def remove_recipient_register(self, email, register_index): if not self._user.is_authenticated or not self._user.can_email(): self._log_warn("Unauthorised user attempting to delete recipient") return UNAUTHORISED recipient = self._recipients_dao.get_recipient(email) name = recipient['name'] test = None ppt = None service = None if str(register_index) == '0': test = False if str(register_index) == '1': ppt = False if str(register_index) == '2': service = False self._recipients_dao.update_recipient(email, name, test, ppt, service) self._log_info("Recipient register removed for " + email) return redirect_url('recipients_api')
def send_music_email(self, service_id, recipients): if not self._user.is_authenticated or not self._user.can_email(): self._log_warn("User not authorised to email services") return UNAUTHORISED service = self._service_dao.get(service_id) template_filename = os.path.join( os.path.dirname(__file__), '../../templates/service_email_template.html') template_file = open(template_filename, 'r').read() template = Template(template_file) body = template.render(service=service, songs=self._songs_dao.get_all()) subject = "Redeemer Music for " + service['date'] self._gmail_client.send(subject, body, recipients, self._user.email) ServiceController._update_email_status(service, 'email_status') self._service_dao.update(service) self._log_info("service email sent for " + str(service['id'])) return redirect_url('services_api')
def send_slides_email(self, service_id, recipients): if not self._user.is_authenticated or not self._user.can_email(): self._log_warn("User not authorised to email slides") return UNAUTHORISED service = self._get_service_from_id(service_id) ppt_filename = powerpoint_location + service[ 'date'] + ' powerpoint.pptx' self._slides_helper.create_powerpoint(service, ppt_filename) template_filename = os.path.join( os.path.dirname(__file__), '../../templates/powerpoint_email_template.html') template_file = open(template_filename, 'r').read() template = Template(template_file) body = template.render(date=service['date']) subject = "Powerpoint slides for " + service['date'] self._gmail_client.send_attachment( subject, body, recipients, self._user.email, ppt_filename, service['date'] + ' powerpoint.pptx') ServiceController._update_email_status(service, 'slides_email_status') self._service_dao.update(service) self._log_info("ppt email sent for " + str(service['id'])) return redirect_url('services_api')