def __init__(self, user_info, is_current_user, current_user_role, role, enabled): super().__init__() self.setupUi(self) self.combo_role.installEventFilter(self) self._role = role self.current_user_role = current_user_role self.is_current_user = is_current_user self.user_info = user_info if self.is_current_user: self.label_name.setText(f"<b>{self.user_info.short_user_display}</b>") else: self.label_name.setText(self.user_info.short_user_display) if self.user_info.human_handle: self.label_email.setText(self.user_info.human_handle.email) if self.user_info.is_revoked: self.setDisabled(True) font = self.label_name.font() font.setStrikeOut(True) self.label_name.setFont(font) self.setToolTip(_("TEXT_WORKSPACE_SHARING_USER_HAS_BEEN_REVOKED")) if not enabled: for role, index in _ROLES_TO_INDEX.items(): self.combo_role.insertItem(index, get_role_translation(role)) else: current_index = _ROLES_TO_INDEX[self.current_user_role] for role, index in _ROLES_TO_INDEX.items(): if current_index < index: break self.combo_role.insertItem(index, get_role_translation(role)) if self.user_info.profile == UserProfile.OUTSIDER and role in ( WorkspaceRole.MANAGER, WorkspaceRole.OWNER, ): item = self.combo_role.model().item(index) item.setEnabled(False) font = item.font() font.setStrikeOut(True) item.setFont(font) item.setToolTip(_("NOT_ALLOWED_FOR_OUTSIDER_PROFILE_TOOLTIP")) self.combo_role.setCurrentIndex(_ROLES_TO_INDEX[self._role]) self.combo_role.currentIndexChanged.connect(self.on_role_changed) self.status_timer = QTimer() self.status_timer.setInterval(3000) self.status_timer.setSingleShot(True) self.status_timer.timeout.connect(self._refresh_status)
def __init__(self, user_info, is_current_user, current_user_role, role, enabled): super().__init__() self.setupUi(self) self.combo_role.installEventFilter(self) self.role = role self.current_user_role = current_user_role self.is_current_user = is_current_user self.user_info = user_info if self.is_current_user: self.label_name.setText(f"<b>{self.user_info.short_user_display}</b>") else: self.label_name.setText(self.user_info.short_user_display) if self.user_info.is_revoked: self.setDisabled(True) font = self.label_name.font() font.setStrikeOut(True) self.label_name.setFont(font) self.setToolTip(_("TEXT_WORKSPACE_SHARING_USER_HAS_BEEN_REVOKED")) if not enabled: for role, index in _ROLES_TO_INDEX.items(): self.combo_role.insertItem(index, get_role_translation(role)) else: current_index = _ROLES_TO_INDEX[self.current_user_role] for role, index in _ROLES_TO_INDEX.items(): if current_index < index: break self.combo_role.insertItem(index, get_role_translation(role)) self.combo_role.setCurrentIndex(_ROLES_TO_INDEX[self.role]) self.combo_role.currentIndexChanged.connect(self.on_role_changed) self.status_timer = QTimer() self.status_timer.setInterval(3000) self.status_timer.setSingleShot(True) self.status_timer.timeout.connect(self._refresh_status)
def _on_sharing_updated_qt(self, new_entry, previous_entry): if new_entry is None or new_entry.role is None: # Sharing revoked show_error( self, _("TEXT_FILE_SHARING_REVOKED_workspace").format( workspace=previous_entry.name)) self.back_clicked.emit() elif previous_entry is not None and previous_entry.role is not None: self.current_user_role = new_entry.role self.label_role.setText( get_role_translation(self.current_user_role)) if (previous_entry.role != WorkspaceRole.READER and new_entry.role == WorkspaceRole.READER): show_error(self, _("TEXT_FILE_SHARING_DEMOTED_TO_READER"))
def apply_state(self, workspace_name, workspace_fs, users_roles, is_mounted, files=None, timestamped=False): # Not meant to change assert timestamped == self.timestamped assert workspace_fs == self.workspace_fs # Update attributes self.workspace_name = workspace_name self.workspace_fs = workspace_fs self.users_roles = users_roles self.files = files or [] # Update dependent widgets if not self.timestamped: if not len(self.files): self.widget_empty.show() self.widget_files.hide() else: self.widget_files.show() self.widget_empty.hide() for i, f in enumerate(files, 1): if i > 4: break label = getattr(self, "file{}_name".format(i)) label.setText(f.str) else: widget_temp = self.widget_empty.layout().itemAt(0).widget() widget_temp.label_timestamp.setText(format_datetime( self.timestamp)) # Retrieve current role for ourself user_id = self.workspace_fs.device.user_id try: current_role, _ = self.users_roles[user_id] except KeyError: current_role = NOT_SHARED_KEY self.label_role.setText(get_role_translation(current_role)) self.label_owner.setVisible(self.is_owner) self.label_shared.setVisible(self.is_shared) self.reload_workspace_name(self.workspace_name) self.set_mountpoint_state(is_mounted)
def set_workspace_fs(self, wk_fs, current_directory=FsPath("/"), default_selection=None): self.current_directory = current_directory self.workspace_fs = wk_fs ws_entry = self.jobs_ctx.run_sync( self.workspace_fs.get_workspace_entry) self.current_user_role = ws_entry.role self.label_role.setText(get_role_translation(self.current_user_role)) self.table_files.current_user_role = self.current_user_role if self.current_user_role == WorkspaceRole.READER: self.button_import_folder.hide() self.button_import_files.hide() self.button_create_folder.hide() else: self.button_import_folder.show() self.button_import_files.show() self.button_create_folder.show() self.clipboard = None self.table_files.paste_disabled = True self.reset(default_selection)
def set_workspace_fs(self, wk_fs, current_directory=FsPath("/"), default_selection=None, clipboard=None): self.table_files.clear() self.current_directory = current_directory self.workspace_fs = wk_fs self.load(current_directory) ws_entry = self.workspace_fs.get_workspace_entry() self.current_user_role = ws_entry.role self.label_role.setText(get_role_translation(self.current_user_role)) self.table_files.current_user_role = self.current_user_role if self.current_user_role == WorkspaceRole.READER: self.button_import_folder.hide() self.button_import_files.hide() self.button_create_folder.hide() else: self.button_import_folder.show() self.button_import_files.show() self.button_create_folder.show() self.clipboard = clipboard if not self.clipboard: self.table_files.paste_status = PasteStatus( status=PasteStatus.Status.Disabled) else: if self.clipboard.source_workspace == self.workspace_fs: self.table_files.paste_status = PasteStatus( status=PasteStatus.Status.Enabled) else: # Sending the source_workspace name for paste text self.table_files.paste_status = PasteStatus( status=PasteStatus.Status.Enabled, source_workspace=self.clipboard.source_workspace. get_workspace_name().str, ) self.reset(default_selection)
def __init__( self, workspace_name, workspace_fs, users_roles, is_mounted, files=None, timestamped=False, reencryption_needs=None, ): super().__init__() self.setupUi(self) self.users_roles = users_roles self.workspace_name = workspace_name self.workspace_fs = workspace_fs self.timestamped = timestamped self.switch_button = SwitchButton() self.widget_actions.layout().insertWidget(0, self.switch_button) self.switch_button.clicked.connect(self._on_switch_clicked) self.reencrypting = None self.reencryption_needs = reencryption_needs self.setCursor(QCursor(Qt.PointingHandCursor)) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.show_context_menu) self.label_role.setText(get_role_translation(self.current_role)) files = files or [] if not self.timestamped: self.button_delete.hide() if not len(files): self.widget_empty.show() self.widget_files.hide() self.widget_empty.layout().addWidget(EmptyWorkspaceWidget()) else: for i, f in enumerate(files, 1): if i > 4: break label = getattr(self, "file{}_name".format(i)) label.setText(f) self.widget_files.show() self.widget_empty.hide() else: self.switch_button.setChecked(True) self.button_reencrypt.hide() self.button_remount_ts.hide() self.button_share.hide() self.button_rename.hide() self.label_shared.hide() self.label_owner.hide() self.switch_button.hide() widg_tmp = TemporaryWorkspaceWidget() widg_tmp.label_timestamp.setText(format_datetime(self.timestamp)) self.widget_empty.layout().addWidget(widg_tmp) self.widget_empty.show() self.widget_files.hide() effect = QGraphicsDropShadowEffect(self) effect.setColor(QColor(0x99, 0x99, 0x99)) effect.setBlurRadius(10) effect.setXOffset(2) effect.setYOffset(2) self.setGraphicsEffect(effect) if not self.is_owner: self.button_reencrypt.hide() self.widget_reencryption.hide() self.button_share.clicked.connect(self.button_share_clicked) self.button_share.apply_style() self.button_reencrypt.clicked.connect(self.button_reencrypt_clicked) self.button_reencrypt.apply_style() self.button_delete.clicked.connect(self.button_delete_clicked) self.button_delete.apply_style() self.button_rename.clicked.connect(self.button_rename_clicked) self.button_rename.apply_style() self.button_remount_ts.clicked.connect(self.button_remount_ts_clicked) self.button_remount_ts.apply_style() self.button_open.clicked.connect(self.button_open_workspace_clicked) self.button_open.apply_style() self.label_owner.apply_style() self.label_shared.apply_style() if not self.is_owner: self.label_owner.hide() if not self.is_shared: self.label_shared.hide() self.reload_workspace_name(self.workspace_name) self.set_mountpoint_state(is_mounted)