Skip to content

Commit

Permalink
Prueba de métodos otorgar permisos
Browse files Browse the repository at this point in the history
  • Loading branch information
uo283840 committed May 1, 2023
1 parent 569d77f commit 67194b5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
4 changes: 2 additions & 2 deletions webapp/src/components/PlaceCard/PlaceCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const PlaceCard = (props) => {

const handleSharePlaceWithAllFriends = () => {
console.log("Boton compartir con todos mis amigos");
giveAllFriendPermissionPoint(session.id, session, place._id);
giveAllFriendPermissionPoint(session.id, session);
};

const handleSharePlaceWithFriend = (event, index) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ const PlaceCard = (props) => {
onClose={handleCloseShareButton}

>
<MenuItem onClick={handleCloseShareButton}>Share with all my friends</MenuItem>
<MenuItem onClick={handleSharePlaceWithAllFriends}>Share with all my friends</MenuItem>
<MenuItem onClick={handleShareOneFriendButton}>Share with a friend of choice</MenuItem>
<MenuItem onClick={handleCloseShareButton}>Option 3</MenuItem>
</Menu>
Expand Down
61 changes: 45 additions & 16 deletions webapp/src/solidapi/solidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { writeData, findDataInContainer, deleteData} from "./solidapi";
import * as solid from "@inrupt/solid-client";
import {FOAF, VCARD} from "@inrupt/lit-generated-vocab-common";
import {
createAclFromFallbackAcl,
getResourceAcl, getSolidDatasetWithAcl,
hasAccessibleAcl,
hasFallbackAcl,
hasResourceAcl, saveAclFor
} from "@inrupt/solid-client";

export function savePlace(session, placeEntity) {
let place = placeEntity;
Expand Down Expand Up @@ -219,37 +226,59 @@ export async function giveFriendPermissionPoint(webId,session, placeId, friendUr
}

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

let friendsURL = solid.getUrlAll(await getProfile(webId), FOAF.knows);
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

let url = urlPlaceUser(webId,placeId); //url del archivo a dar permisos

try { //obtener el archivo de control de acceso para la cuenta de usuario
let file = await solid.getFile(
url,
{ fetch: session.fetch }
);
try {
for(let friend in friendsURL){
let name =extractNameFromUrl(webId);
console.log("name corto :"+name)
const myDatasetWithAcl = await getSolidDatasetWithAcl( "https://"+name +".inrupt.net/private/Places/", {
fetch: session.fetch
});

//recorremos el array de amigos para compartir el sitio con todos los amigos
for(let friend in friendsURL){ //para cada amigo
let resourceAcl = solid.createAcl(file); //se crea un objeto de control de acceso

// for(let friend in friendsURL){ //para cada amigo
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,
friendsURL[friend],
{ read: true, append: false, write: true, control: false }
friend,
{ read: true, append: false, write: false, control: false }
);

await solid.saveAclFor(file, updatedAcl, { fetch: session.fetch }); //se guardan en cada amigo los cambios
console.log("Permisos al amigo :"+ friendsURL);
await saveAclFor(myDatasetWithAcl, updatedAcl, { fetch: session.fetch }); //se guardan en cada amigo los cambios
console.log("Permisos al amigo :"+ friend);
}

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

export async function extractNameFromUrl(url) {
let start = url.indexOf("//") + 2;
let end = url.indexOf(".", start);
return url.substring(start, end);
}



export async function getProfile(webId){
Expand Down

0 comments on commit 67194b5

Please sign in to comment.