Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: 98 transfer collection ownership grant resource access #155

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/scrape_collection_from_hummedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def migrate_collection(args):
TIMESTAMP = datetime.now().isoformat(timespec='seconds')
print('Sending output to {TIMESTAMP}.log...')

with open(f'{TIMESTAMP}.log', 'w') as log_file, open(f'{TIMESTAMP}-complete.txt', 'w') as c_file, open(f'{TIMESTAMP}-partial.txt', 'w') as p_file:
with open(f'logs/{TIMESTAMP}.log', 'w') as log_file, open(f'logs/{TIMESTAMP}-complete.txt', 'w') as c_file, open(f'logs/{TIMESTAMP}-partial.txt', 'w') as p_file:
log_file = sys.stdout # override log_file
print(args, file=log_file)
print(BATCH_IDS, file=log_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,16 @@
404 (:body {:message string?})}
:handler (fn [{{{:keys [id]} :path} :parameters}]
(methods/collection-get-all-users id))})

(def collection-transfer-ownership
{:summary "Tranfers ownership of collection to specified username"
:permission-level "admin"
:parameters {:header {:session-id uuid?}
:path {:id uuid?
:username string?}}
:responses {200 {:body {:message string?
:id string?}}
500 {:body {:message string?}}}
:handler (fn [{{{:keys [id username]} :path} :parameters}]
(methods/collection-transfer-ownership id username))
})
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,19 @@
{:status 200
:body user-result})))






(defn collection-transfer-ownership
[id username]
(if (not (collections/EXISTS? id))
{:status 404
:body {:message "collection not found"}}
;; TODO add logic here
;; 1. Change `owner` in public.collection
;; 2. Get all resources for which the new owner does not have permissions using the following
;; SELECT resource_id from public.contents WHERE collection_id = uuid('<COLLECTION_ID>')
;; AND resource_id NOT IN (SELECT resource_id from public.resource_access
;; WHERE resource_id IN (SELECT resource_id from public.contents
;; WHERE collection_id = uuid('<COLLECTION_ID>'))
;; AND username LIKE '<username>')
;; 3. For every resource_id identified above, add username to resource_access table
;; * Factor out the handler in resource-handlers/resource-add-access and use the new function here
)
5 changes: 4 additions & 1 deletion src/clj/y_video_back/routes/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@
["/{id}/courses"
{:get service-handlers/collection-get-all-courses}]
["/{id}/users"
{:get service-handlers/collection-get-all-users}]]
{:get service-handlers/collection-get-all-users}]
["/{id}/transfer/{username}"
{:get service-handlers/collection-transfer-ownership}]
]

["/course"
{:swagger {:tags ["course"]}}
Expand Down
Loading