|
6 | 6 |
|
7 | 7 | from ...common import is_dc_resource_dict |
8 | 8 |
|
9 | | -from ..tools import ShowWaitCursor |
10 | | -from ..api import get_ckan_api |
11 | | - |
12 | 9 |
|
13 | 10 | class FilterChain(QtWidgets.QWidget): |
14 | 11 | download_item = QtCore.pyqtSignal(str, str, bool) |
@@ -125,138 +122,3 @@ def update_resources(self): |
125 | 122 | else: |
126 | 123 | rs_entries.append(rs) |
127 | 124 | self.fw_resources.set_entries(rs_entries) |
128 | | - |
129 | | - |
130 | | -class FilterChainUser(FilterChain): |
131 | | - added_datasets_to_collection = QtCore.pyqtSignal(dict, list) |
132 | | - share_item = QtCore.pyqtSignal(str, str) |
133 | | - |
134 | | - def __init__(self, *args, **kwargs): |
135 | | - """Filter chain with user-related features""" |
136 | | - super(FilterChainUser, self).__init__(*args, **kwargs) |
137 | | - |
138 | | - # Enable the "add to collection tool box" |
139 | | - self.fw_datasets.pushButton_custom.setText( |
140 | | - "Add selected datasets to a collection...") |
141 | | - self.fw_datasets.pushButton_custom.setVisible(True) |
142 | | - self.fw_datasets.pushButton_custom.clicked.connect( |
143 | | - self.on_add_datasets_to_collection) |
144 | | - |
145 | | - # Enable share buttons for collections and datasets |
146 | | - self.fw_datasets.active_actions.append("share") |
147 | | - self.fw_collections.active_actions.append("share") |
148 | | - self.fw_datasets.share_item.connect(self.on_share_dataset) |
149 | | - self.fw_collections.share_item.connect(self.on_share_collections) |
150 | | - |
151 | | - def choose_collaborator(self, what_for=None): |
152 | | - """Let the user choose a collaborator from a dropdown list""" |
153 | | - # Fetch a list of users |
154 | | - with ShowWaitCursor(): |
155 | | - api = get_ckan_api() |
156 | | - # TODO: let the user search for collaborators and add them to a |
157 | | - # memoized list. |
158 | | - users = api.get("user_autocomplete", q="", limit=100) |
159 | | - |
160 | | - for_what_for = f" for {what_for}" |
161 | | - label = f"Please choose a collaborator{for_what_for}." |
162 | | - ignored_users = ["default", "adminpaul", api.user_name] |
163 | | - user_choices = sorted([ |
164 | | - f"{u['fullname'] or u['name'].capitalize()} ({u['name']})" |
165 | | - for u in users if u["name"] not in ignored_users]) |
166 | | - item, ok = QtWidgets.QInputDialog.getItem( |
167 | | - self, |
168 | | - "Choose a user", |
169 | | - label, |
170 | | - user_choices, |
171 | | - 0, # current index |
172 | | - False, # editable |
173 | | - ) |
174 | | - if ok: |
175 | | - username = item.rsplit("(", 1)[1].strip(")") |
176 | | - return username |
177 | | - else: |
178 | | - return None |
179 | | - |
180 | | - @QtCore.pyqtSlot() |
181 | | - def on_add_datasets_to_collection(self): |
182 | | - """Add all datasets currently selected to a collection |
183 | | -
|
184 | | - Displays a dialog where the user can choose a collection |
185 | | - they have write-access to. |
186 | | - """ |
187 | | - # get current selection |
188 | | - dataset_ids = self.fw_datasets.get_entry_identifiers(selected=True) |
189 | | - if not dataset_ids: |
190 | | - # no datasets selected |
191 | | - QtWidgets.QMessageBox.information( |
192 | | - self, "No datasets selected", |
193 | | - "Please select at least one dataset.") |
194 | | - else: |
195 | | - # get list of writable collections |
196 | | - with ShowWaitCursor(): |
197 | | - api = get_ckan_api() |
198 | | - grps = api.get("group_list_authz") |
199 | | - grps = sorted(grps, key=lambda x: x["display_name"]) |
200 | | - item, ok = QtWidgets.QInputDialog.getItem( |
201 | | - self, |
202 | | - "Select a collection", |
203 | | - f"Please choose a collection for {len(dataset_ids)} datasets.", |
204 | | - [f"{ii}: {g['display_name']}" for ii, g in enumerate(grps)], |
205 | | - 0, # current index |
206 | | - False, # editable |
207 | | - ) |
208 | | - if ok: |
209 | | - index = int(item.split(":")[0]) |
210 | | - collection = grps[index] |
211 | | - with ShowWaitCursor(): |
212 | | - # add all datasets to that collection |
213 | | - for did in dataset_ids: |
214 | | - api.post( |
215 | | - "member_create", |
216 | | - data={"id": collection["id"], |
217 | | - "object": did, |
218 | | - "object_type": "package", |
219 | | - # "capacity" should not be necessary |
220 | | - # https://github.com/ckan/ckan/issues/6543 |
221 | | - "capacity": "member"}) |
222 | | - self.added_datasets_to_collection.emit(collection, |
223 | | - dataset_ids) |
224 | | - |
225 | | - @QtCore.pyqtSlot(str, str) |
226 | | - def on_share_collections(self, id_type, identifier): |
227 | | - """Share a collection with a collaborator""" |
228 | | - if id_type != "collection": |
229 | | - raise ValueError( |
230 | | - "`on_share_collections` only works for collections") |
231 | | - |
232 | | - # TODO: Let user list and remove collaborators |
233 | | - |
234 | | - user = self.choose_collaborator(f"collection {identifier}") |
235 | | - |
236 | | - if user: |
237 | | - api = get_ckan_api() |
238 | | - api.post("member_create", |
239 | | - data={"id": identifier, |
240 | | - "object": user, |
241 | | - "object_type": "user", |
242 | | - "capacity": "member"}) |
243 | | - # TODO: add a success message in the status widget |
244 | | - |
245 | | - @QtCore.pyqtSlot(str, str) |
246 | | - def on_share_dataset(self, id_type, identifier): |
247 | | - """Share a collection with another user""" |
248 | | - if id_type != "dataset": |
249 | | - raise ValueError( |
250 | | - "`on_share_dataset` only works for datasets") |
251 | | - |
252 | | - # TODO: Let user list and remove collaborators |
253 | | - |
254 | | - user = self.choose_collaborator(f"dataset {identifier}") |
255 | | - |
256 | | - if user: |
257 | | - api = get_ckan_api() |
258 | | - api.post("package_collaborator_create", |
259 | | - data={"id": identifier, |
260 | | - "user_id": user, |
261 | | - "capacity": "member"}) |
262 | | - # TODO: add a success message in the status widget |
0 commit comments