Skip to content

Commit

Permalink
Conseguido dar permiso a la carpeta de Places cuando compartes un sitio.
Browse files Browse the repository at this point in the history
  • Loading branch information
uo283840 committed May 1, 2023
1 parent ce4c5c6 commit 327af39
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
4 changes: 0 additions & 4 deletions webapp/src/components/PlaceCard/PlaceCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const PlaceCard = (props) => {
setSnackbarOpenShare(false);
};



const handleDeletePlace = () => {
console.log(place.id);

Expand All @@ -94,8 +92,6 @@ const PlaceCard = (props) => {
handleSnackbarOpenShare();
};



return (
<div>
<Card style={{margin: '25px', marginTop:'0px'}}>
Expand Down
65 changes: 43 additions & 22 deletions webapp/src/solidapi/solidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ export function savePlace(session, placeEntity) {
let privacyOfPlace = place.privacy;
console.log(privacyOfPlace);
let PlacesUrl = basicUrl.concat("/private", "/Places", "/" + place.id + ".json");
//
// let PlacesUrlPublic ="";

// if(privacyOfPlace === "Public"){
// PlacesUrlPublic = basicUrl.concat("/public", "/Places", "/" + place.id + ".json");
// PlacesUrl = basicUrl.concat("/private", "/Places", "/" + place.id + ".json");
// }else if(privacyOfPlace === "Private") {
// PlacesUrl = basicUrl.concat("/private", "/Places", "/" + place.id + ".json");
// }


place = JSON.parse(JSON.stringify(place))
Expand All @@ -38,17 +29,9 @@ export function savePlace(session, placeEntity) {
place["@type"] = "Place";



let blob = new Blob([JSON.stringify(place)],{ type: "application/ld+json" });
let file = new File([blob], place.id + ".jsonld", { type: blob.type });


//le paso el file creado con el blob
// if(privacyOfPlace === "Public") { //si es publico se guarda en la carpeta de contenido privado y en la de público
// writeData(session,PlacesUrl,file);
// writeData(session,PlacesUrlPublic,file);
//
// }else {
writeData(session,PlacesUrl,file);

//}
Expand Down Expand Up @@ -225,23 +208,23 @@ export async function giveFriendPermissionPoint(webId,session, placeId, friendUr
}
}

//Funcion que da permiso sobre un punto a todos los amigos
//Función que da permiso sobre un punto a todos los amigos
export async function giveAllFriendPermissionPoint(webId,session, placeID) {

let myDataset = await solid.getSolidDataset(webId); // obtain the dataset from the URI
let theThing = await solid.getThing(myDataset, webId);
let friendsURL = solid.getUrlAll(theThing, FOAF.knows); //array de amigos
console.log(friendsURL);
let name =extractNameFromUrl(webId);
console.log("name corto :"+name)
try {
for(let i in friendsURL){
console.log(i);
let name =extractNameFromUrl(webId);
console.log("name corto :"+name)
giveFriendPermissionFolder(webId,session,name);
const myDatasetWithAcl = await getSolidDatasetWithAcl( "https://"+name +".inrupt.net/private/Places/"+placeID+".json", {
fetch: session.fetch
});


let resourceAcl;
if (!hasResourceAcl(myDatasetWithAcl)) {
if (!hasAccessibleAcl(myDatasetWithAcl)) {
Expand All @@ -261,7 +244,7 @@ export async function giveAllFriendPermissionPoint(webId,session, placeID) {
const updatedAcl = solid.setAgentResourceAccess( //se establecen los permisos
resourceAcl,
friendsURL[i],
{ read: true, append: true, write: false, control: false }
{ read: true, append: true , write: true, control: false }
);

await saveAclFor(myDatasetWithAcl, updatedAcl, { fetch: session.fetch }); //se guardan en cada amigo los cambios
Expand All @@ -273,6 +256,44 @@ export async function giveAllFriendPermissionPoint(webId,session, placeID) {
}
}

//Función que otorga permisos a los amigos para la carpeta places, y asi poder monstrar los sitios que se compartieron.
export async function giveFriendPermissionFolder(webId,session, friendUrl, userName) {
try {
console.log("permisos carpeta");
const myDatasetWithAcl = await getSolidDatasetWithAcl( "https://"+userName +".inrupt.net/private/Places/.acl", {
fetch: session.fetch
});
let resourceAcl;
if (!hasResourceAcl(myDatasetWithAcl)) {
if (!hasAccessibleAcl(myDatasetWithAcl)) {
console.log(
"The current user does not have permission to change access rights to this Resource."
);
}
if (!hasFallbackAcl(myDatasetWithAcl)) {
console.log(
"The current user does not have permission to see who currently has access to this Resource."
);
}
resourceAcl = createAclFromFallbackAcl(myDatasetWithAcl);
} else {
resourceAcl = getResourceAcl(myDatasetWithAcl);
}
const updatedAcl = solid.setAgentResourceAccess( //se establecen los permisos
resourceAcl,
friendUrl,
{ read: true, append: true, write: false, control: false }
);

await saveAclFor(myDatasetWithAcl, updatedAcl, { fetch: session.fetch }); //se guardan en cada amigo los cambios
console.log("Permisos al amigo carpeta:"+ friendUrl +" de la carpeta Places.");
// }

} catch (error) {
console.log(error);
}
}

export function extractNameFromUrl(url) {
let start = url.indexOf("//") + 2;
let end = url.indexOf(".", start);
Expand Down
5 changes: 2 additions & 3 deletions webapp/src/solidapi/solidapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
async function writeData(session, url, file) {
let result = true;
try {


await overwriteFile(
url,
file,
Expand Down Expand Up @@ -67,7 +65,8 @@ async function deleteData(session, url) {
return result;
}

async function updateData(url, webId, session) {


}

export { writeData, findDataInContainer , deleteData};

0 comments on commit 327af39

Please sign in to comment.