`
+ if(fsentry.owner.username === window.user.username)
+ perm_list += `You (${fsentry.owner.email ?? fsentry.owner.username})`;
+ else
+ perm_list += fsentry.owner.email ?? fsentry.owner.username;
+ perm_list += `
owner
`;
+ perm_list += `
`;
+ // add this user to the list of printed users
+ printed_users.push(fsentry.owner.username);
+ }
+
+ if(recipients.length > 0){
+ recipients.forEach((recipient) => {
+ // others with access
+ if(recipients.length > 0){
+ recipients.forEach(perm => {
+ //check if this user has been printed here before, important for multiple items
+ if(!printed_users.includes(perm.user.username)){
+ perm_list += ``
+ perm_list += `${perm.user.email ?? perm.user.username}`;
+ perm_list += `
✕
`;
+ perm_list += `
`;
+ // add this user to the list of printed users
+ printed_users.push(perm.user.username);
+ }
+ });
+ }
+ });
+ }
+ $(el_window).find('.share-recipients').append(`${perm_list}`);
+ }).
+ catch((err) => {
+ console.error(err);
})
}
- // if(perms.length > 0){
- // let printed_users = [];
- // let perm_list = '';
- // perms.forEach(fsentry => {
- // //owner
- // //check if this user has been printed here before, important for multiple items
- // if(!printed_users.includes(fsentry.owner.username)){
- // perm_list += ``
- // if(fsentry.owner.username === window.user.username)
- // perm_list += `You (${fsentry.owner.email ?? fsentry.owner.username})`;
- // else
- // perm_list += fsentry.owner.email ?? fsentry.owner.username;
- // perm_list += `
owner
`;
- // perm_list += `
`;
- // // add this user to the list of printed users
- // printed_users.push(fsentry.owner.username);
- // }
-
- // // others with access
- // if(fsentry.permissions.length > 0){
- // fsentry.permissions.forEach(perm => {
- // //check if this user has been printed here before, important for multiple items
- // if(!printed_users.includes(perm.username)){
- // perm_list += ``
- // perm_list += `${perm.email ?? perm.username}`;
- // perm_list += `
✕
`;
- // perm_list += `
`;
- // // add this user to the list of printed users
- // printed_users.push(perm.username);
- // }
- // });
- // }
- // });
- // $(el_window).find('.share-recipients').append(`${perm_list}`);
- // }
$(el_window).find('.give-access-btn').on('click', async function(e){
e.preventDefault();
@@ -155,25 +150,46 @@ async function UIWindowShare(items){
let cancelled_due_to_error = false;
let share_result;
+ let access_level = 'write';
$.ajax({
- url: puter.APIOrigin + "/share/item-by-username",
+ url: puter.APIOrigin + "/share",
type: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + puter.authToken
},
data: JSON.stringify({
- path: items[0].path,
- username: recipient_username
+ recipients:[
+ recipient_username
+ ],
+ paths: [
+ {
+ path: items[0].path,
+ access_level: access_level,
+ }
+ ]
}),
success: function(response) {
// show success message
$(el_window).find('.access-recipient-print').html(recipient_id);
$(el_window).find('.window-give-item-access-success').show(100);
+ let perm_id = `fs:${items[0].uid}:${access_level}`;
+
+ // append recipient to list
+ let perm_list = '';
+ perm_list += ``
+ perm_list += `${recipient_username}`;
+ perm_list += `
✕
`;
+ perm_list += `
`;
+
+ // append recipient to list
+ $(el_window).find('.share-recipients').append(`${perm_list}`);
+
+ // add this user to the list of printed users
+ // printed_users.push(perm.user.username);
},
error: function(err) {
- console.error(err);
// at this point 'username_not_found' and 'shared_with_self' are the only
// errors that need to stop the loop
if(err.responseJSON.code === "user_does_not_exist" || err.responseJSON.code === 'shared_with_self'){
@@ -204,4 +220,24 @@ async function UIWindowShare(items){
})
}
+$(document).on('click', '.remove-permission-link', async function(){
+ let recipient_username = $(this).attr('data-recipient-username');
+ let permission = $(this).attr('data-permission');
+
+ fetch(puter.APIOrigin + "/auth/revoke-user-user", {
+ "headers": {
+ "Content-Type": "application/json",
+ "Authorization": `Bearer ${puter.authToken}`,
+ },
+ "body": JSON.stringify({
+ permission: permission,
+ target_username: recipient_username
+ }),
+ "method": "POST"
+ }).then((response) => {
+ $('.item-perm-recipient-card[data-permission="'+permission+'"]').remove();
+ }).catch((err) => {
+ console.error(err);
+ })
+})
export default UIWindowShare
\ No newline at end of file