das-cli 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
das/cli.py CHANGED
@@ -221,6 +221,8 @@ def search_entries(das_ctx, attribute, query, max_results, page, sort_by, sort_o
221
221
  def get_entry(das_ctx, entry_id, output_format):
222
222
  """Get detailed information about a single entry by ID"""
223
223
  try:
224
+ # Ensure client and entry_manager are initialized
225
+ das_ctx.get_client()
224
226
  # Reusing the entry manager to get entry details by ID
225
227
  entry = das_ctx.entry_manager.get_entry(entry_id)
226
228
 
@@ -318,6 +320,8 @@ def update_entry(das_ctx, attribute, code=None, file_path=None, data=None):
318
320
  das entry update --attribute core --data [{ 'Code': 'ENT001', ... }, { 'Code': 'ENT002', ... }]
319
321
  """
320
322
  try:
323
+ # Ensure client and entry_manager are initialized
324
+ das_ctx.get_client()
321
325
  if not file_path and not data:
322
326
  raise click.UsageError("Please provide either a file path or data string")
323
327
 
@@ -437,6 +441,8 @@ def create_entry(das_ctx, attribute, file_path=None, data=None):
437
441
  das entry create --attribute core --data [{ 'Name': 'Entry 1', ... }, { 'Name': 'Entry 2', ... }]
438
442
  """
439
443
  try:
444
+ # Ensure client and entry_manager are initialized
445
+ das_ctx.get_client()
440
446
  if not file_path and not data:
441
447
  raise click.UsageError("Please provide either a file path or data string")
442
448
 
@@ -514,6 +520,8 @@ def get_entry(das_ctx, code=None, id=None):
514
520
  raise click.UsageError("Please provide either an entry code or ID")
515
521
 
516
522
  try:
523
+ # Ensure client and entry_manager are initialized
524
+ das_ctx.get_client()
517
525
  # Pass client as a named parameter to avoid conflicts with 'id' parameter
518
526
  entry = das_ctx.entry_manager.get(code=code, id=id)
519
527
  if entry:
@@ -549,6 +557,38 @@ def get_entry(das_ctx, code=None, id=None):
549
557
  except Exception as e:
550
558
  click.secho(f"Error: {e}", fg="red")
551
559
 
560
+ @entry.command("chown")
561
+ @click.option('--user', 'user_name', required=True, help='New owner username')
562
+ @click.option('--code', '-c', multiple=True, required=True, help='Entry code to transfer. Can be used multiple times.')
563
+ @pass_das_context
564
+ def chown_entries(das_ctx, user_name, code):
565
+ """Change ownership of one or more entries by their codes.
566
+
567
+ Example:
568
+
569
+ \b
570
+ das entry chown --user alice --code ENT001 --code ENT002
571
+ """
572
+ try:
573
+ # Ensure services are initialized
574
+ das_ctx.get_client()
575
+
576
+ entry_codes = list(code)
577
+ if not entry_codes:
578
+ raise click.UsageError("Please provide at least one --code")
579
+
580
+ result = das_ctx.entry_manager.chown(user_name=user_name, entry_code_list=entry_codes)
581
+
582
+ # If API returns a plain success or list, just report success
583
+ click.secho("✓ Ownership updated successfully!", fg="green")
584
+ if isinstance(result, dict):
585
+ # Show minimal feedback if available
586
+ updated = result.get('updated') or result.get('result') or result
587
+ if updated:
588
+ click.echo(json.dumps(updated, indent=2))
589
+ except Exception as e:
590
+ click.secho(f"Error: {e}", fg="red")
591
+
552
592
  # Attribute commands group
553
593
  @cli.group()
554
594
  def attribute():
@@ -6,6 +6,7 @@ from das.services.entry_fields import EntryFieldsService
6
6
  from das.services.entries import EntriesService
7
7
  from das.common.entry_fields_constants import DIGITAL_OBJECT_INPUT, SELECT_COMBO_INPUT
8
8
  from das.services.search import SearchService
9
+ from das.services.users import UsersService
9
10
 
10
11
 
11
12
  class EntryManager:
@@ -20,6 +21,7 @@ class EntryManager:
20
21
  self.entry_fields_service = EntryFieldsService(base_url)
21
22
  self.search_service = SearchService(base_url)
22
23
  self.attribute_service = AttributesService(base_url)
24
+ self.user_service = UsersService(base_url)
23
25
 
24
26
  def get_entry(self, entry_id: str):
25
27
  """Get entry details by ID"""
@@ -425,6 +427,27 @@ class EntryManager:
425
427
  else:
426
428
  raise ValueError("Unsupported file type. Supported types are: .json, .csv, .xlsx")
427
429
 
430
+ def chown(self, user_name: str, entry_code_list: list[str]):
431
+
432
+ user = self.user_service.get_user(user_name)
433
+
434
+ if user is None:
435
+ raise ValueError(f"User '{user_name}' not found")
436
+
437
+ if not entry_code_list:
438
+ raise ValueError("Entry code list is required")
439
+
440
+ entry_list_ids = []
441
+
442
+ for entry_code in entry_code_list:
443
+ entry = self.get(code=entry_code)
444
+ entry_list_ids.append(entry.get('ID') if entry.get('ID') else entry.get('id'))
445
+
446
+ if not entry_list_ids:
447
+ raise ValueError("Entry list IDs is empty")
448
+
449
+ return self.entry_service.chown(new_user_id=user.get('id'), entry_list_ids=entry_list_ids)
450
+
428
451
  if __name__ == "__main__":
429
452
  manager = EntryManager()
430
453
  entry = manager.get(id="8d2841c9-e307-4971-bd2b-70da0d7a7534")
das/services/entries.py CHANGED
@@ -130,3 +130,29 @@ class EntriesService():
130
130
  else:
131
131
  raise ValueError(response.get('error'))
132
132
 
133
+ def chown(self, new_user_id: int, entry_list_ids: list[str]):
134
+ """Change the owner of a list of entries."""
135
+ token = load_token()
136
+
137
+ if (token is None or token == ""):
138
+ raise ValueError("Authorization token is required")
139
+
140
+ headers = {
141
+ "Authorization": f"Bearer {token}",
142
+ "Content-Type": "application/json"
143
+ }
144
+
145
+ url = f"{self.base_url}/ChangeOwner"
146
+
147
+ payload = {
148
+ "newOwnerId": new_user_id,
149
+ "entryIdList": entry_list_ids
150
+ }
151
+
152
+ response = post_data(url, data=payload, headers=headers)
153
+
154
+ if response.get('success') == True:
155
+ return response.get('result')
156
+ else:
157
+ raise ValueError(response.get('error'))
158
+
das/services/users.py ADDED
@@ -0,0 +1,25 @@
1
+ from das.common.api import delete_data, get_data, post_data, put_data
2
+ from das.common.config import load_token
3
+
4
+ class UsersService:
5
+ def __init__(self, base_url):
6
+ self.base_url = f"{base_url}/api/services/app/User"
7
+
8
+ def get_user(self, user_name: str):
9
+ token = load_token()
10
+
11
+ if (token is None or token == ""):
12
+ raise ValueError("Authorization token is required")
13
+
14
+ headers = {
15
+ "Authorization": f"Bearer {token}"
16
+ }
17
+
18
+ url = f"{self.base_url}/GetUsers?filter={user_name}"
19
+
20
+ response = get_data(url, headers=headers)
21
+
22
+ if response.get('success') == True:
23
+ return response.get('result').get('items')[0]
24
+ else:
25
+ raise ValueError(response.get('error'))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  das/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  das/app.py,sha256=kKxN4Vn84SA5Ph3zY13avMG2vrUp-ffpdDkhwYR9Bho,1475
3
- das/cli.py,sha256=stQC3SJnkqJ2hCQnpXfz9lRZ0BYHUAivFG0fYoCzDIM,42446
3
+ das/cli.py,sha256=pQJVVrhXF_hJ9IwcKXyb96LB50EXfpUYtTSeCV2LLw4,44006
4
4
  das/ai/plugins/dasai.py,sha256=R0X0Vey_GOAtWoqcloB-NATZFtXB_l5b9dfPXocNIbI,2165
5
5
  das/ai/plugins/entries/entries_plugin.py,sha256=Dhv6PrguQj5mzxBW6DlCzkmwucszazLQfzwlp9EhIGk,608
6
6
  das/authentication/auth.py,sha256=DTtH66Ft6nuuMe7EYvrr3GqGVEGGxE7GmD2fO7vRv4s,1501
@@ -12,18 +12,19 @@ das/common/enums.py,sha256=jS0frv6717duG_wZNockXMTZ-VfsGu_f8_-lgYGnrcY,1745
12
12
  das/common/file_utils.py,sha256=-zePjYsj8iRpQssVQMHDK3Mh5q8FooKJCUCKCXKS6_Y,7006
13
13
  das/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  das/managers/download_manager.py,sha256=NqaLhmjw-4nZq8SVdN0g5MAnbMPEnu-A3A4oXxQ-IZQ,3776
15
- das/managers/entries_manager.py,sha256=FommEjTue1dlVeV-lw3mueiPlPbA3NrYwC9cfcbEutg,18166
15
+ das/managers/entries_manager.py,sha256=Kc_PN71Bp7VICrxoP9MiDCrUzR7OdUXfX5puDDxtm08,19015
16
16
  das/managers/search_manager.py,sha256=ba3fYiLEdkgeOmPr0j5XRMq29DrQTsrPRGDMJCznvHk,3485
17
17
  das/services/attributes.py,sha256=78E9f1wNZYxG9Hg5HfX_h1CFmACaMjwD2Y6Ilb7PJGY,2616
18
18
  das/services/cache.py,sha256=g-vY51gqGV_1Vpza476PkMqGpuDNo1NbTwQWIIsvO0s,1932
19
19
  das/services/downloads.py,sha256=LDjPaYDQf0-XmMtC_FjDhHLsPBw1_vfUMwSfRMycyqA,2977
20
- das/services/entries.py,sha256=rXkhLOk0ls5GYQCn5ONVji6BlEmtO7T94FYSTpOH2Qk,4164
20
+ das/services/entries.py,sha256=Uspl7LZcNWEnr7ct5_Kn31jMjrkSKV7UXzrN6nb3HF0,4966
21
21
  das/services/entry_fields.py,sha256=x2wUDkKNduj9pf4s56hRo0UW-eBhipkU9gFMEjFw5DA,1290
22
22
  das/services/hangfire.py,sha256=hidmVP9yb4znzBaJJRyKawYx7oYaBv5OVL-t0BhvN_A,818
23
23
  das/services/search.py,sha256=3X_KPb9fs024FhxoTr4j-xY5ymm5rvvzlekxuh8tLdg,1374
24
- das_cli-1.0.0.dist-info/licenses/LICENSE,sha256=4EDhysVgQWBlzo0rdUl_k89s-iVfgCcSa1gUx1TM1vA,1124
25
- das_cli-1.0.0.dist-info/METADATA,sha256=BU88knb18IFVUOQ4KWFjpwzzsw9DBp6cI3t_JFIMycI,10469
26
- das_cli-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- das_cli-1.0.0.dist-info/entry_points.txt,sha256=ZrdMae7NcvogQhzM1zun8E8n_QwYq-LpZvoJCr2_I4g,36
28
- das_cli-1.0.0.dist-info/top_level.txt,sha256=OJsPEeJyJ2rJlpEn2DTPgbMSvYG-6FeD13_m5qLpw3E,4
29
- das_cli-1.0.0.dist-info/RECORD,,
24
+ das/services/users.py,sha256=iNijO2UPIEtcpPy8Tkemdxxym9rYLCUyckQHIQj68W0,795
25
+ das_cli-1.0.2.dist-info/licenses/LICENSE,sha256=4EDhysVgQWBlzo0rdUl_k89s-iVfgCcSa1gUx1TM1vA,1124
26
+ das_cli-1.0.2.dist-info/METADATA,sha256=87BZw_7pywe8pQY-f-obe9j0lQjyC5hfY9bSNzBrN9Q,10469
27
+ das_cli-1.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ das_cli-1.0.2.dist-info/entry_points.txt,sha256=ZrdMae7NcvogQhzM1zun8E8n_QwYq-LpZvoJCr2_I4g,36
29
+ das_cli-1.0.2.dist-info/top_level.txt,sha256=OJsPEeJyJ2rJlpEn2DTPgbMSvYG-6FeD13_m5qLpw3E,4
30
+ das_cli-1.0.2.dist-info/RECORD,,