Beispiel #1
0
 def get_by_id(user_id: int,
               with_bookmarks: bool = False) -> Optional[User]:
     user_data = Db.get_by_id(user_id)
     if user_data:
         return User(user_data,
                     Db.get_bookmarks(user_id) if with_bookmarks else None)
     return None  # pragma no cover - something went wrong, e.g. obsolete session values
Beispiel #2
0
 def toggle_bookmark(entity_id: int) -> str:
     if int(entity_id) in current_user.bookmarks:
         Db.delete_bookmark(current_user.id, entity_id)
         label = _('bookmark')
     else:
         Db.insert_bookmark(current_user.id, entity_id)
         label = _('bookmark remove')
     return label
Beispiel #3
0
 def update_settings(self, form: Any) -> None:
     for field in form:
         if field.type in ['CSRFTokenField', 'HiddenField', 'SubmitField'] or \
                 field.name in ['name', 'email']:
             continue
         value = field.data
         if field.type == 'BooleanField':
             value = 'True' if value else ''
         Db.update_settings(self.id, field.name, value)
Beispiel #4
0
 def update(self) -> None:
     Db.update({
         'id': self.id,
         'username': self.username,
         'real_name': self.real_name,
         'password': self.password,
         'info': self.description,
         'email': self.email,
         'active': self.active,
         'group_name': self.group,
         'login_last_success': self.login_last_success,
         'login_last_failure': self.login_last_failure,
         'login_failed_count': self.login_failed_count,
         'unsubscribe_code': self.unsubscribe_code,
         'password_reset_code': self.password_reset_code,
         'password_reset_date': self.password_reset_date
     })
Beispiel #5
0
 def get_settings(user_id: int) -> Dict[str, Any]:
     settings = {
         'layout': 'default',
         'language': session['language'],
         'newsletter': False,
         'table_show_aliases': True,
         'show_email': False
     }
     for setting in session['settings']:
         if setting in ['map_zoom_max', 'map_zoom_default', 'table_rows'] or \
                 setting.startswith('module_'):
             settings[setting] = session['settings'][setting]
     for row in Db.get_settings(user_id):
         settings[row['name']] = row['value']
         if row['name'] in ['table_rows']:
             settings[row['name']] = int(row['value'])
     return settings
Beispiel #6
0
 def insert(form: FlaskForm) -> int:
     return Db.insert({
         'username':
         form.username.data,
         'real_name':
         form.real_name.data,
         'info':
         form.description.data,
         'email':
         form.email.data,
         'active':
         form.active.data,
         'group_name':
         form.group.data,
         'password':
         bcrypt.hashpw(form.password.data.encode('utf-8'),
                       bcrypt.gensalt()).decode('utf-8')
     })
Beispiel #7
0
 def get_note_by_id(id_: int) -> Dict[str, Any]:
     return Db.get_note_by_id(id_)
Beispiel #8
0
 def get_notes_by_user_id(user_id: int) -> List[Dict[str, Any]]:
     return Db.get_notes_by_user_id(user_id)
Beispiel #9
0
 def insert_note(entity_id: int, note: str, public: bool) -> None:
     from openatlas.util.display import sanitize
     Db.insert_note(current_user.id, entity_id, sanitize(note, 'text'),
                    public)
Beispiel #10
0
 def update_note(id_: int, note: str, public: bool) -> None:
     from openatlas.util.display import sanitize
     Db.update_note(id_, sanitize(note, 'text'), public)
Beispiel #11
0
 def update_language(self) -> None:
     Db.update_language(self.id, current_user.settings['language'])
Beispiel #12
0
 def get_by_reset_code(code: str) -> Optional[User]:
     user_data = Db.get_by_reset_code(code)
     return User(user_data) if user_data else None
Beispiel #13
0
 def get_all() -> List[User]:
     return [User(row) for row in Db.get_all()]
Beispiel #14
0
 def update_settings(self, settings: dict[str, Any]) -> None:
     for name, value in settings.items():
         Db.update_settings(self.id, name, value)
Beispiel #15
0
 def get_activities(limit: int, user_id: int,
                    action: str) -> List[Dict[str, Any]]:
     return Db.get_activities(limit, user_id, action)
Beispiel #16
0
 def get_created_entities_count(user_id: int) -> int:
     return Db.get_created_entities_count(user_id)
Beispiel #17
0
 def get_by_unsubscribe_code(code: str) -> Optional[User]:
     user_data = Db.get_by_unsubscribe_code(code)
     return User(user_data) if user_data else None
Beispiel #18
0
 def get_by_username(username: str) -> Optional[User]:
     user_data = Db.get_by_username(username)
     return User(user_data) if user_data else None
Beispiel #19
0
 def get_by_email(email: str) -> Optional[User]:
     user_data = Db.get_by_email(email)
     return User(user_data) if user_data else None
Beispiel #20
0
 def delete_note(id_: int) -> None:
     Db.delete_note(id_)
Beispiel #21
0
 def get_users_for_form() -> list[tuple[int, str]]:
     return Db.get_users_for_form()
Beispiel #22
0
 def get_by_id(user_id: int, bookmarks: bool = False) -> Optional[User]:
     if user_data := Db.get_by_id(user_id):
         return User(user_data,
                     Db.get_bookmarks(user_id) if bookmarks else None)
Beispiel #23
0
 def insert_note(entity_id: int, note: str, public: bool) -> None:
     Db.insert_note(current_user.id, entity_id, sanitize(note, 'text'),
                    public)
Beispiel #24
0
 def remove_newsletter(self) -> None:
     Db.remove_newsletter(self.id)
Beispiel #25
0
 def toggle_bookmark(entity_id: int) -> str:
     if int(entity_id) in current_user.bookmarks:
         Db.delete_bookmark(current_user.id, entity_id)
         return 'bookmark'
     Db.insert_bookmark(current_user.id, entity_id)
     return 'bookmark remove'
Beispiel #26
0
 def get_notes_by_entity_id(self, entity_id: int) -> List[Dict[str, Any]]:
     return Db.get_notes_by_entity_id(self.id, entity_id)
Beispiel #27
0
 def update_note(id_: int, note: str, public: bool) -> None:
     Db.update_note(id_, sanitize(note, 'text'), public)
Beispiel #28
0
 def get_users_for_form() -> List[Tuple[int, str]]:
     return Db.get_users_for_form()
Beispiel #29
0
 def insert(data: dict[str, Any]) -> int:
     return Db.insert(data)