def admin_profile(self): def scaffold_before_validate(**kwargs): parser = kwargs['parser'] item = kwargs['item'] change_level = item.get_role_level() item.old_password = item.password item.new_password = parser.data['password'] def validate(): try: _validate = parser.container.validate() if _validate: return parser.container except: return False # parser.validate = validate def bycrypt_password(**kwargs): item = kwargs['item'] item.bycrypt_password_with_old_password() self.context['change_view_to_view_function'] = '' self.events.scaffold_before_validate += scaffold_before_validate self.events.scaffold_after_save += bycrypt_password self.Scaffold.hidden_in_form.append('is_enable') return scaffold.edit(self, self.application_user.key)
def admin_edit(self, key): def scaffold_before_validate(**kwargs): parser = kwargs['parser'] item = kwargs['item'] item.old_password = item.password item.new_password = parser.data['password'] self.logging.debug(item.new_password) def validate(): if self.application_user_level < self.target_level: parser.errors['role'] = u'您的權限等級低於此角色' return False return parser.container.validate( ) if parser.container else False parser.validate = validate def bycrypt_password(**kwargs): item = kwargs['item'] item.bycrypt_password_with_old_password() if self.check_level(self.params.get_ndb_record(key)) is False: return self.abort(403) self.events.scaffold_before_validate += scaffold_before_validate self.events.scaffold_after_save += bycrypt_password if self.target.key == self.application_user.key: self.Scaffold.hidden_in_form.append('is_enable') return scaffold.edit(self, key)
def admin_edit(self, key, *args): def scaffold_before_validate(**kwargs): parser = kwargs['parser'] change_level = self.params.get_integer('level') def validate(): if self.application_user_level < target_level: parser.errors['level'] = u"您的權限等級 (%s) 低於目標值 (%s),您無法設置比您高等級的角色" % (self.application_user_level, target_level) return False if self.application_user_level < change_level: parser.errors['level'] = u"您的權限等級 (%s) 低於設定值 (%s),您無法設置比您高等級的值" % (self.application_user_level, change_level) return False if change_level > 1000 < self.application_user_level and target_level != 9999: parser.errors['level'] = u'權限等級最高為 999' return False if target_level == 9999 and change_level != 9999: parser.errors['level'] = u'此權限等級無法變更' return False return parser.container.validate() if parser.container else False parser.validate = validate target = self.params.get_ndb_record(key) target_level = target.level self.application_user_level = self.application_user.get_role_level() if self.application_user_level < target_level: return self.abort(403) self.events.scaffold_before_validate += scaffold_before_validate self.context['application_user_level'] = self.application_user_level return scaffold.edit(self, key)
def admin_config(self): self.context['application_id'] = app_identity.get_application_id() self.meta.view.template_name = '/mail/config.html' config_record = self.meta.Model.get_config() return scaffold.edit(self, config_record.key)
def admin_config(self): config_record = self.meta.Model.get_config() return scaffold.edit(self, config_record.key)
def admin_edit(self, key): namespace_manager.set_namespace('shared') return scaffold.edit(self, key)
def admin_config(self): config_record = self.meta.Model.get_config() self.events.scaffold_after_save += self.change_config return scaffold.edit(self, config_record.key)
def admin_edit(self, key): return scaffold.edit(self, key)