def execute_updated_user_actions(self, user: User) -> None: """ WARNING ! This method Will be Deprecated soon, see https://github.com/tracim/tracim/issues/1589 and https://github.com/tracim/tracim/issues/1487 This method do post-update user actions """ # FIXME - G.M - 2019-03-18 - move this code to another place when # event mecanism is ready, see https://github.com/tracim/tracim/issues/1487 # event on_updated_user should start hook use by agenda app code. if self._config.CALDAV__ENABLED: agenda_api = AgendaApi(current_user=self._user, session=self._session, config=self._config) try: agenda_api.ensure_user_agenda_exists(user) except AgendaServerConnectionError as exc: logger.error(self, "Cannot connect to agenda server") logger.exception(self, exc) except Exception as exc: logger.error( self, "Something goes wrong during agenda create/update") logger.exception(self, exc)
def execute_update_workspace_actions(self, workspace: Workspace) -> None: """ WARNING ! This method Will be Deprecated soon, see https://github.com/tracim/tracim/issues/1589 and https://github.com/tracim/tracim/issues/1487 This method do post update workspace actions """ # FIXME - G.M - 2019-03-18 - move this code to another place when # event mecanism is ready, see https://github.com/tracim/tracim/issues/1487 # event on_updated_workspace should start hook use by agenda app code. # TODO - G.M - 2019-04-11 - Circular Import, will probably be remove # with event refactor, see https://github.com/tracim/tracim/issues/1487 from tracim_backend.lib.agenda.agenda import AgendaApi if self._config.CALDAV__ENABLED: if workspace.agenda_enabled: agenda_api = AgendaApi(current_user=self._user, session=self._session, config=self._config) try: agenda_api.ensure_workspace_agenda_exists(workspace) except AgendaServerConnectionError as exc: logger.error(self, "Cannot connect to agenda server") logger.exception(self, exc) except Exception as exc: logger.error( self, "Something goes wrong during agenda create/update") logger.exception(self, exc)
def user_agendas(self, context, request: TracimRequest, hapic_data=None): app_config = request.registry.settings["CFG"] # type: CFG agenda_api = AgendaApi(current_user=request.current_user, session=request.dbsession, config=app_config) return agenda_api.get_user_agendas( request.candidate_user, workspaces_ids_filter=hapic_data.query.workspace_ids, agenda_types_filter=hapic_data.query.agenda_types, )
def execute_created_user_actions(self, user: User) -> None: """ WARNING ! This method Will be Deprecated soon, see https://github.com/tracim/tracim/issues/1589 and https://github.com/tracim/tracim/issues/1487 This method do post-create user actions """ # TODO - G.M - 04-04-2018 - [auth] # Check if this is already needed with # new auth system user.ensure_auth_token( validity_seconds=self._config.USER__AUTH_TOKEN__VALIDITY) # FIXME - G.M - 2019-03-18 - move this code to another place when # event mecanism is ready, see https://github.com/tracim/tracim/issues/1487 # event on_created_user should start hook use by agenda app code. if self._config.CALDAV__ENABLED: agenda_api = AgendaApi(current_user=self._user, session=self._session, config=self._config) try: agenda_already_exist = agenda_api.ensure_user_agenda_exists( user) if agenda_already_exist: logger.warning( self, "user {} is just created but his own agenda already exist !!" .format(user.user_id), ) except AgendaServerConnectionError as exc: logger.error(self, "Cannot connect to agenda server") logger.exception(self, exc) except Exception as exc: logger.error( self, "Something goes wrong during agenda create/update") logger.exception(self, exc)
def take_app_action(self, parsed_args: argparse.Namespace, app_context: AppEnvironment) -> None: # TODO - G.M - 05-04-2018 -Refactor this in order # to not setup object var outside of __init__ . self._session = app_context["request"].dbsession self._app_config = app_context["registry"].settings["CFG"] self._user_api = UserApi(current_user=None, session=self._session, config=self._app_config) self._workspace_api = WorkspaceApi(current_user=None, force_role=True, session=self._session, config=self._app_config) self._agenda_api = AgendaApi(current_user=None, session=self._session, config=self._app_config) # INFO - G.M - 2019-03-13 - check users agendas users = self._user_api.get_all() nb_error_agenda_access = 0 for user in users: try: already_exist = self._agenda_api.ensure_user_agenda_exists( user) if not already_exist: print("New created agenda for user {}".format(user)) except CannotCreateAgenda as exc: nb_error_agenda_access += 1 print("Cannot create agenda for user {}".format(user.user_id)) logger.exception(self, exc) except AgendaServerConnectionError as exc: nb_error_agenda_access += 1 print("Cannot access to agenda server: connection error.") logger.exception(self, exc) except Exception as exc: nb_error_agenda_access += 1 print("Something goes wrong during agenda create/update") logger.exception(self, exc) nb_user_agendas = len(users) nb_verified_user_agenda = len(users) - nb_error_agenda_access print("{}/{} users agenda verified".format(nb_verified_user_agenda, nb_user_agendas)) # # INFO - G.M - 2019-03-13 - check workspaces agendas workspaces = self._workspace_api.get_all() nb_error_agenda_access = 0 nb_workspaces = 0 nb_agenda_enabled_workspace = 0 for workspace in workspaces: nb_workspaces += 1 if workspace.agenda_enabled: nb_agenda_enabled_workspace += 1 try: already_exist = self._agenda_api.ensure_workspace_agenda_exists( workspace) if not already_exist: print("New created agenda for workspace {}".format( workspace.workspace_id)) except CannotCreateAgenda as exc: print("Cannot create agenda for workspace {}".format( workspace.workspace_id)) logger.exception(self, exc) except AgendaServerConnectionError as exc: nb_error_agenda_access += 1 print("Cannot access to agenda server: connection error.") logger.exception(self, exc) nb_verified_workspace_agenda = nb_agenda_enabled_workspace - nb_error_agenda_access nb_workspace_without_agenda_enabled = nb_workspaces - nb_agenda_enabled_workspace print( "{}/{} workspace agenda verified ({} workspace without agenda feature enabled)" .format( nb_verified_workspace_agenda, nb_agenda_enabled_workspace, nb_workspace_without_agenda_enabled, ))