Skip to content

Commit bc52721

Browse files
authored
Merge pull request #230 from rkvst/mmwilder26/jpn_sharingalbumrelease
Sharing Album Release Info and skip clause
2 parents 79d83e6 + bac9f76 commit bc52721

File tree

4 files changed

+264
-0
lines changed

4 files changed

+264
-0
lines changed
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "f1578ab4-c4c4-4811-8315-fe4bda4aed0b",
6+
"metadata": {},
7+
"source": [
8+
"## Sharing Album Release Info with User"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "fa53b861-8b8a-42a8-9654-b7d6ccf4c71a",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"# Creates an Access Policy that shares event-level \"read-only\" permission with user (within a single tenancy).\n",
19+
"#\n",
20+
"# Main function, establishes a connection to RKVST using an App Registration then uses that\n",
21+
"# to create an Access Policy.\n",
22+
"#\n",
23+
"# Note: The purpose of RKVST Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.\n",
24+
"# The RKVST Python SDK is authored to work cleanly with more advanced coding techniques.\n",
25+
"#\n",
26+
"# RKVST Python SDK: https://github.com/rkvst/rkvst-python\n",
27+
"#"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 2,
33+
"id": "38b7b338-33d9-410c-8775-6668160f6b6d",
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"import random\n",
38+
"import string\n",
39+
"\n",
40+
"from json import dumps as json_dumps\n",
41+
"from os import getenv\n",
42+
"from warnings import filterwarnings\n",
43+
"\n",
44+
"from dotenv import load_dotenv\n",
45+
"\n",
46+
"from archivist.archivist import Archivist\n",
47+
"from archivist.proof_mechanism import ProofMechanism\n",
48+
"from archivist.logger import set_logger\n",
49+
"from archivist.constants import ASSET_BEHAVIOURS"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 3,
55+
"id": "0a42d850-572b-4fc0-bb39-9c84e527a59c",
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"%reload_ext dotenv\n",
60+
"%dotenv -o notebooks.env"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 4,
66+
"id": "bf389f55-d494-4d0e-a6bd-29b8b7423be4",
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.\n",
71+
"#\n",
72+
"# RKVST_URL = represents the url to the RKVST application\n",
73+
"# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration\n",
74+
"# RKVST_APPREG_SECRET = represents the client secret from an Application Registration\n",
75+
"RKVST_URL = getenv(\"RKVST_URL\")\n",
76+
"RKVST_APPREG_CLIENT = getenv(\"RKVST_APPREG_CLIENT\")\n",
77+
"RKVST_APPREG_SECRET = getenv(\"RKVST_APPREG_SECRET\")"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": 5,
83+
"id": "39ae54a5-4a9e-4710-8342-a98ea7c60c6a",
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"name": "stdout",
88+
"output_type": "stream",
89+
"text": [
90+
"Connecting to RKVST\n",
91+
"RKVST_URL https://app.rkvst.io\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"\"\"\"\n",
97+
"Main function of Access Policy creation.\n",
98+
"\n",
99+
"* Connect to RKVST with client ID and client secret\n",
100+
"* Creates an Access Policy\n",
101+
"* Prints response of Access Policy creation\n",
102+
"\"\"\"\n",
103+
"\n",
104+
"# Optional call to set the logger level. The argument can be either\n",
105+
"# \"INFO\" or \"DEBUG\". For more sophisticated logging control see our\n",
106+
"# documentation.\n",
107+
"set_logger(\"INFO\")\n",
108+
"\n",
109+
"# Initialize connection to RKVST\n",
110+
"print(\"Connecting to RKVST\")\n",
111+
"print(\"RKVST_URL\", RKVST_URL)\n",
112+
"arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": 6,
118+
"id": "4d6728f5-eef5-4956-b60c-c66f2fdd0b28",
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"def create_event_access(arch):\n",
123+
" \"\"\"\n",
124+
" Creates an Access Policy that shares Album Release data for Artists with another user within a single tenancy\n",
125+
" \"\"\"\n",
126+
" props = {\n",
127+
" \"display_name\": \"Sharing Album Release\",\n",
128+
" \"description\": \"Sharing Album Release Information\",\n",
129+
" }\n",
130+
" filters = [{\"or\": [\"attributes.arc_display_type=Artists\"]}]\n",
131+
" access_permissions = [\n",
132+
" {\n",
133+
" \"asset_attributes_read\": [\n",
134+
" \"arc_display_name\",\n",
135+
" \"arc_display_type\",\n",
136+
" \"arc_description\",\n",
137+
" ],\n",
138+
" \"asset_attributes_write\": [],\n",
139+
" \"behaviours\": ASSET_BEHAVIOURS,\n",
140+
" \"event_arc_display_type_read\": [\"Album Release\"],\n",
141+
" \"event_arc_display_type_write\": [],\n",
142+
" \"include_attributes\": [],\n",
143+
" \"subjects\": [],\n",
144+
" \"user_attributes\": [{\"or\": [\"[email protected]\"]}],\n",
145+
" }\n",
146+
" ]\n",
147+
"\n",
148+
" return arch.access_policies.create(props, filters, access_permissions)"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": 7,
154+
"id": "edbd3d74-895c-4ba5-aa1d-68a675da6cbe",
155+
"metadata": {},
156+
"outputs": [
157+
{
158+
"name": "stderr",
159+
"output_type": "stream",
160+
"text": [
161+
"Refresh token\n"
162+
]
163+
},
164+
{
165+
"name": "stdout",
166+
"output_type": "stream",
167+
"text": [
168+
"ACCESS_POLICY {\n",
169+
" \"identity\": \"access_policies/f62f414b-ad42-456e-855a-4820fb34dfb4\",\n",
170+
" \"display_name\": \"Sharing Album Release\",\n",
171+
" \"filters\": [\n",
172+
" {\n",
173+
" \"or\": [\n",
174+
" \"attributes.arc_display_type=Artists\"\n",
175+
" ]\n",
176+
" }\n",
177+
" ],\n",
178+
" \"access_permissions\": [\n",
179+
" {\n",
180+
" \"subjects\": [],\n",
181+
" \"behaviours\": [\n",
182+
" \"Attachments\",\n",
183+
" \"RecordEvidence\"\n",
184+
" ],\n",
185+
" \"include_attributes\": [],\n",
186+
" \"user_attributes\": [\n",
187+
" {\n",
188+
" \"or\": [\n",
189+
190+
" ]\n",
191+
" }\n",
192+
" ],\n",
193+
" \"asset_attributes_read\": [\n",
194+
" \"arc_display_name\",\n",
195+
" \"arc_display_type\",\n",
196+
" \"arc_description\"\n",
197+
" ],\n",
198+
" \"asset_attributes_write\": [],\n",
199+
" \"event_arc_display_type_read\": [\n",
200+
" \"Album Release\"\n",
201+
" ],\n",
202+
" \"event_arc_display_type_write\": []\n",
203+
" }\n",
204+
" ],\n",
205+
" \"tenant\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\",\n",
206+
" \"description\": \"Sharing Album Release Information\"\n",
207+
"}\n"
208+
]
209+
}
210+
],
211+
"source": [
212+
"# Creates an Access Policy and prints result\n",
213+
"access_policy = create_event_access(arch)\n",
214+
"print(\"ACCESS_POLICY\", json_dumps(access_policy, indent=4))"
215+
]
216+
}
217+
],
218+
"metadata": {
219+
"kernelspec": {
220+
"display_name": "Python 3 (ipykernel)",
221+
"language": "python",
222+
"name": "python3"
223+
},
224+
"language_info": {
225+
"codemirror_mode": {
226+
"name": "ipython",
227+
"version": 3
228+
},
229+
"file_extension": ".py",
230+
"mimetype": "text/x-python",
231+
"name": "python",
232+
"nbconvert_exporter": "python",
233+
"pygments_lexer": "ipython3",
234+
"version": "3.8.15"
235+
}
236+
},
237+
"nbformat": 4,
238+
"nbformat_minor": 5
239+
}

docs/notebooks.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Download the notebooks into a suitable folder:
6464
:caption: Access Policy Examples
6565

6666
notebooks/Sharing Artist Asset with User
67+
notebooks/Sharing Album Release Info with User
6768

6869
.. toctree::
6970
:maxdepth: 2

functests/execnotebooks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,17 @@ def test_share_artist_asset_user(self):
262262
self.basic_notebook_test(notebook)
263263
self.check_notebook_cell(notebook, 7)
264264
LOGGER.debug("=================================")
265+
266+
@skip("Requires root access credentials -- see #7742")
267+
def test_share_album_release_user(self):
268+
"""
269+
Test share_album_release_user
270+
"""
271+
with testbook(
272+
"archivist/notebooks/Sharing Album Release Info with User.ipynb",
273+
execute=True,
274+
) as notebook:
275+
LOGGER.debug("\nshare_album_release_user")
276+
self.basic_notebook_test(notebook)
277+
self.check_notebook_cell(notebook, 7)
278+
LOGGER.debug("=================================")

unittests/testnotebooks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,13 @@ def test_share_artist_asset_user(self):
279279
execute=range(1, 6),
280280
) as notebook:
281281
self.basic_notebook_test(notebook)
282+
283+
def test_share_album_release_user(self):
284+
"""
285+
Test share_album_release_user
286+
"""
287+
with testbook(
288+
"archivist/notebooks/Sharing Album Release Info with User.ipynb",
289+
execute=range(1, 6),
290+
) as notebook:
291+
self.basic_notebook_test(notebook)

0 commit comments

Comments
 (0)