async def test_workspace_button_shared_with(qtbot, workspace_fs, client_config,
                                            bob, alice_user_info,
                                            bob_user_info):
    switch_language(client_config, "en")

    roles = {
        bob.user_id: (WorkspaceRole.READER, bob_user_info),
        alice_user_info.user_id: (WorkspaceRole.OWNER, alice_user_info),
    }
    w = WorkspaceButton(
        workspace_name="Workspace",
        workspace_fs=workspace_fs,
        users_roles=roles,
        is_mounted=True,
        files=[],
    )

    qtbot.addWidget(w)
    w.show()
    assert w.widget_empty.isVisible() is True
    assert w.label_owner.isVisible() is True
    assert w.label_shared.isVisible() is True
    assert w.name == "Workspace"
    assert w.label_title.text().startswith("Workspace")
    assert w.label_title.toolTip() == "Workspace (shared with Boby McBobFace)"
    assert w.label_role.text() == _("TEXT_WORKSPACE_ROLE_OWNER")
async def test_workspace_button_files(qtbot, workspace_fs, client_config,
                                      alice_user_info):
    switch_language(client_config, "en")

    roles = {alice_user_info.user_id: (WorkspaceRole.OWNER, alice_user_info)}
    w = WorkspaceButton(
        workspace_name="Workspace",
        workspace_fs=workspace_fs,
        users_roles=roles,
        is_mounted=True,
        files=[],
    )

    qtbot.addWidget(w)
    w.show()
    assert w.widget_empty.isVisible() is True
    assert w.label_owner.isVisible() is True
    assert w.label_shared.isVisible() is False
    assert w.name == "Workspace"
Exemple #3
0
    def add_workspace(self, workspace_fs, ws_entry, users_roles, files,
                      timestamped):

        # The Qt thread should never hit the client directly.
        # Synchronous calls can run directly in the job system
        # as they won't block the Qt loop for long
        workspace_name = self.jobs_ctx.run_sync(
            workspace_fs.get_workspace_name)

        # Temporary code to fix the workspace names edited by
        # the previous naming policy (the userfs used to add
        # `(shared by <device>)` at the end of the workspace name)
        token = " (shared by "
        if token in workspace_name:
            workspace_name, *_ = workspace_name.split(token)
            self.jobs_ctx.submit_job(
                ThreadSafeQtSignal(self, "ignore_success", QtToTrioJob),
                ThreadSafeQtSignal(self, "ignore_error", QtToTrioJob),
                _do_workspace_rename,
                client=self.client,
                workspace_id=workspace_fs.workspace_id,
                new_name=workspace_name,
                button=None,
            )
        button = WorkspaceButton(
            workspace_name=workspace_name,
            workspace_fs=workspace_fs,
            users_roles=users_roles,
            is_mounted=self.is_workspace_mounted(workspace_fs.workspace_id,
                                                 None),
            files=[],
            timestamped=timestamped,
        )
        self.layout_workspaces.addWidget(button)
        button.clicked.connect(self.load_workspace)
        button.share_clicked.connect(self.share_workspace)
        button.reencrypt_clicked.connect(self.reencrypt_workspace)
        button.delete_clicked.connect(self.delete_workspace)
        button.rename_clicked.connect(self.rename_workspace)
        button.remount_ts_clicked.connect(self.remount_workspace_ts)
        button.open_clicked.connect(self.open_workspace)
        button.switch_clicked.connect(self._on_switch_clicked)

        self.jobs_ctx.submit_job(
            ThreadSafeQtSignal(self, "reencryption_needs_success",
                               QtToTrioJob),
            ThreadSafeQtSignal(self, "reencryption_needs_error", QtToTrioJob),
            _get_reencryption_needs,
            workspace_fs=workspace_fs,
        )
async def test_workspace_button_delete_clicked(qtbot, workspace_fs,
                                               client_config, alice_user_info):
    switch_language(client_config, "en")

    roles = {alice_user_info.user_id: (WorkspaceRole.OWNER, alice_user_info)}
    w = WorkspaceButton(
        workspace_name="Workspace",
        workspace_fs=workspace_fs,
        users_roles=roles,
        is_mounted=True,
        files=[],
    )
    qtbot.addWidget(w)
    with qtbot.waitSignal(w.delete_clicked, timeout=500) as blocker:
        qtbot.mouseClick(w.button_delete, QtCore.Qt.LeftButton)
    assert blocker.args == [workspace_fs]