예제 #1
0
파일: workspace.py 프로젝트: gehasia/tracim
    def ensure_calendar_exist(self, workspace: Workspace) -> None:
        # Note: Cyclic imports
        from tracim.lib.calendar import CalendarManager
        from tracim.model.organisational import WorkspaceCalendar

        calendar_manager = CalendarManager(self._user)

        try:
            calendar_manager.enable_calendar_file(
                calendar_class=WorkspaceCalendar,
                related_object_id=workspace.workspace_id,
                raise_=True,
            )
        # If previous calendar file no exist, calendar must be created
        except FileNotFoundError:
            self._user.ensure_auth_token()

            # Ensure database is up-to-date
            DBSession.flush()
            transaction.commit()

            calendar_manager.create_then_remove_fake_event(
                calendar_class=WorkspaceCalendar,
                related_object_id=workspace.workspace_id,
            )
예제 #2
0
파일: workspace.py 프로젝트: gehasia/tracim
    def disable_calendar(self, workspace: Workspace) -> None:
        # Note: Cyclic imports
        from tracim.lib.calendar import CalendarManager
        from tracim.model.organisational import WorkspaceCalendar

        calendar_manager = CalendarManager(self._user)
        calendar_manager.disable_calendar_file(
            calendar_class=WorkspaceCalendar,
            related_object_id=workspace.workspace_id,
            raise_=False,
        )
예제 #3
0
    def ensure_calendar_exist(self, workspace: Workspace) -> None:
        # Note: Cyclic imports
        from tracim.lib.calendar import CalendarManager
        from tracim.model.organisational import WorkspaceCalendar

        if workspace.calendar_enabled:
            self._user.ensure_auth_token()

            # Ensure database is up-to-date
            DBSession.flush()
            transaction.commit()

            calendar_manager = CalendarManager(self._user)
            calendar_manager.create_then_remove_fake_event(
                calendar_class=WorkspaceCalendar,
                related_object_id=workspace.workspace_id,
            )
예제 #4
0
파일: user.py 프로젝트: qyqx/tracim
    def execute_created_user_actions(self, created_user: User) -> None:
        """
        Execute actions when user just been created
        :return:
        """
        # NOTE: Cyclic import
        from tracim.lib.calendar import CalendarManager
        from tracim.model.organisational import UserCalendar

        created_user.ensure_auth_token()

        # Ensure database is up-to-date
        DBSession.flush()
        transaction.commit()

        calendar_manager = CalendarManager(created_user)
        calendar_manager.create_then_remove_fake_event(
            calendar_class=UserCalendar,
            related_object_id=created_user.user_id,
        )
예제 #5
0
def authorized(user, collection, permission):
    """
    :param user: radicale given user id, should be email
    :param collection: Calendar representation
    :param permission: 'r' or 'w'
    :return: True if user can access calendar with asked permission
    """
    if not user:
        return False
    current_user = UserApi(None).get_one_by_email(user)
    manager = CalendarManager(current_user)

    if manager.is_discovery_path(collection.path):
        return True

    try:
        calendar = manager.find_calendar_with_path(collection.path)
    except NotFound:
        return False

    if permission == CALENDAR_PERMISSION_READ:
        return calendar.user_can_read(current_user)
    return calendar.user_can_write(current_user)
예제 #6
0
    def calendar_url(self) -> str:
        # TODO - 20160531 - Bastien: Cyclic import if import in top of file
        from tracim.lib.calendar import CalendarManager
        calendar_manager = CalendarManager(None)

        return calendar_manager.get_workspace_calendar_url(self.workspace_id)
예제 #7
0
파일: storage.py 프로젝트: qyqx/tracim
 def __init__(self, path: str, principal: bool = False):
     super().__init__(path, principal)
     self._replacing = False  # See ``replacing`` context manager
     self._manager = CalendarManager(Auth.current_user)