Skip to content

Commit

Permalink
Merge pull request #202 from Arquisoft/manuel
Browse files Browse the repository at this point in the history
Arreglado el error que he cometido al sobreescribir el código de Adriana
  • Loading branch information
uo283840 authored Apr 20, 2023
2 parents d0ba4c1 + d67cd4a commit e4a4c19
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 74 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/AddPlaceSidebar/AddPlaceSidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState} from 'react';
import {Button, FormControl, MenuItem, Select, Alert, SnackBar, Snackbar} from "@mui/material";
import {Button, FormControl, MenuItem, Select, Alert, Snackbar} from "@mui/material";
import TextField from "@mui/material/TextField";
import useStyles from "./styles";
import PlaceEntity from "../../entities/PlaceEntity";
Expand Down
11 changes: 7 additions & 4 deletions webapp/src/components/DetailsSidebar/DetailsSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import {Typography} from "@mui/material";
import SettingsSideBar from "../SettingsSideBar/SettingsSideBar";
import ProfileSideBar from "../ProfileSideBar/ProfileSideBar";
import SocialSidebar from "../SocialSidebar/SocialSidebar";
import { FOAF } from '@inrupt/lit-generated-vocab-common';
import {getFriends, getPlacesByWebId} from "../../solidapi/solidAdapter";
import CommentsSidebar from "../CommentsSidebar/CommentsSidebar";

const DetailsSidebar = (props) => {
const classes = useStyles();
const [content, setContent] = useState("");
const [setContent] = useState("");
const {places, setPlaces, selectedPoint, setSelectedPoint, setSelectedButton, selectedButton,setSelectedPlaceMyPlaces,
deletePlace, setPlacesLength,userWebId, session, selectedFriendPlaces, setSelectedFriendPlaces, deleteFriend} = props;
const [selectedFriend, setSelectedFriend] = useState([]);
const [selectedPlaceComment, setSelectedPlaceComment] = useState([]);
const [showDeleteButton, setShowDeleteButton] =useState(true);
const [showDeleteButton] =useState(true);
const selectedFriendUsername = selectedFriend.friendURL?.split("/")[2].split(".")[0]

useEffect(() => {
Expand Down Expand Up @@ -72,7 +71,11 @@ const DetailsSidebar = (props) => {
Explore your friends places.
</Typography>
<div style={{ overflow: "auto", height: "70vh" }}>
<SocialSidebar userWebId={userWebId} setSelectedFriend={setSelectedFriend} setSelectedButton={setSelectedButton} deleteFriend={deleteFriend}/>
<SocialSidebar userWebId={userWebId}
setSelectedFriend={setSelectedFriend}
setSelectedButton={setSelectedButton}
deleteFriend={deleteFriend}
session = {session}/>
</div>
</>
);
Expand Down
12 changes: 2 additions & 10 deletions webapp/src/components/FriendCard/FriendCard.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Card, CardContent, CardHeader, IconButton, Menu, MenuItem, Typography} from "@mui/material";
import {Card, CardHeader, IconButton, Typography} from "@mui/material";
import DeleteRoundedIcon from '@mui/icons-material/DeleteRounded';
import MapIcon from '@mui/icons-material/Map';
import Avatar from "@mui/material/Avatar";
Expand All @@ -11,7 +11,7 @@ import { deleteFriendPod } from '../../solidapi/solidAdapter';

const FriendCard = (props) => {
const classes = useStyles();
const {friend, setSelectedFriend, setSelectedButton, deleteFriend, userWebId} = props;
const {friend, setSelectedFriend, setSelectedButton, userWebId} = props;
const [open, setOpen] = React.useState(false);

const friendUrl = friend.friendURL;
Expand All @@ -28,10 +28,8 @@ const FriendCard = (props) => {
const handleDeleteFriend = () => {
console.log("DELETING FRIEND...");
deleteFriendPod(userWebId, "https://uo282249.inrupt.net/profile/card#me"); //deleting in the frontend

}

// console.log(friend.profilePicture);
return (
<div>
<CombinedDataProvider datasetUrl={friendUrl} thingUrl={friendUrl}>
Expand Down Expand Up @@ -60,12 +58,6 @@ const FriendCard = (props) => {
title={<Typography variant="h5" style={{fontWeight: "bold"}}>{friend.friendName}</Typography>}
subheader={<Typography variant="h6" color="textSecondary">{part}</Typography>}
/>
{/*<CardContent component="div" style={{paddingTop: '0px'}} >*/}
{/* <Typography variant="body2" component="p">*/}
{/* /!*{place.description}*!/*/}
{/* */}
{/* </Typography>*/}
{/*</CardContent>*/}
</Card>
<DeleteFriendConfirmDialog open={open} handleClose={handleClose} handleDeleteFriend={handleDeleteFriend}/>
</CombinedDataProvider>
Expand Down
9 changes: 0 additions & 9 deletions webapp/src/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ const Map = (props) => {

{showAddPlaceMarker()}

//{/*{places?.map((place) => (
<Marker key={place.id} position={{lat: place.latitude, lng: place.longitude}} icon={blueIcon}>
<Popup>
<div><Typography variant="subtitle1">{place.name} | {place.category}</Typography></div>
<div><Typography variant="subtitle3">{place.description}</Typography></div>
</Popup>
</Marker>
// ))}*/}

{showPlaces()}

</MapContainer>
Expand Down
6 changes: 2 additions & 4 deletions webapp/src/components/MyPlacesSidebar/MyPlacesSidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react';
import {Typography} from "@mui/material";
import useStyles from "./styles";
import PlaceCard from "../PlaceCard/PlaceCard";
import {Marker, Popup} from "react-leaflet";
import List from '@mui/material/List';

const MyPlacesSidebar = (props) => {
const {places, setPlaces,setSelectedPlaceMyPlaces, deletePlace, session, showDeleteButton, setSelectedPlaceComment,
const {setSelectedPlaceMyPlaces, deletePlace, session, showDeleteButton, setSelectedPlaceComment,
setSelectedButton} = props;
const classes = useStyles();

Expand Down
4 changes: 1 addition & 3 deletions webapp/src/components/PlaceCard/PlaceCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
CardContent,
CardHeader,
IconButton,
Menu,
MenuItem,
Typography,
Chip,
Alert,
Expand Down Expand Up @@ -48,7 +46,7 @@ const PlaceCard = (props) => {

console.log("El id que buscará en el pod es: " + place.id) //correcto, asi lo tenemos guardado en los pods por ahora
//no se si los guiones que separan en el log, y en la web de los pods no aparecen, afectan
removePlace(session,place.id)//TODO delete from the pods
removePlace(session,place.id)// delete from the pods
deletePlaceMarkByID(place._id); //deleting in the database

deletePlace(place.id); //deleting in the frontend
Expand Down
3 changes: 1 addition & 2 deletions webapp/src/components/ProfileSideBar/ProfileSideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import ListItem from '@mui/material/ListItem';
import Card from '@mui/material/Card';
import {Alert, Button, CardContent, Snackbar, Typography} from "@mui/material";
import {
useSession,
CombinedDataProvider,
Image,
Text,
} from "@inrupt/solid-ui-react";
import { FOAF, VCARD } from "@inrupt/lit-generated-vocab-common";
import { VCARD } from "@inrupt/lit-generated-vocab-common";

const ProfileSideBar = (props) => {
const classes = useStyles();
Expand Down
5 changes: 1 addition & 4 deletions webapp/src/components/SocialSidebar/SocialSidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, {useEffect, useState} from 'react';
import useStyles from "./styles";
import PlaceCard from "../PlaceCard/PlaceCard";
import {getFriends} from "../../solidapi/solidAdapter";
import {getFriends, giveFriendsPermissions} from "../../solidapi/solidAdapter";
import FriendCard from "../FriendCard/FriendCard";

const SocialSidebar = (props) => {
// const classes = useStyles();
const {userWebId, setSelectedFriend,setSelectedButton, deleteFriend} = props;
const [friends, setFriends] = useState([]);
useEffect(() => {
Expand Down
142 changes: 105 additions & 37 deletions webapp/src/solidapi/solidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import PlaceEntity from "../entities/PlaceEntity";

import { writeData, findDataInContainer, deleteData} from "./solidapi";
import { writeData, findDataInContainer, deleteData} from "./solidapi";
import * as solid from "@inrupt/solid-client";
import {FOAF, VCARD} from "@inrupt/lit-generated-vocab-common";
import {
getSolidDataset,
saveSolidDatasetAt,
removeUrlFromThing,
getThing,
getUrlAll,
setThing, getNamedNode
} from '@inrupt/solid-client';

export function savePlace(session, placeEntity) {
let place = placeEntity;
Expand All @@ -26,12 +16,12 @@ export function savePlace(session, placeEntity) {
let PlacesUrl ="";
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");
}
// 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 @@ -46,14 +36,14 @@ export function savePlace(session, placeEntity) {


//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
// 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);
writeData(session,PlacesUrlPublic,file);

}else {
writeData(session,PlacesUrl,file);

}
//}
return place;
}

Expand Down Expand Up @@ -91,13 +81,14 @@ export async function removePlace(session,placeId){
const basicUrl = session.info.webId?.split("/").slice(0, 3).join("/");
const placeUrl = basicUrl.concat("/private", "/Places", "/" + placeToDelete.id + ".json");

if (placeToDelete.privacy === "Public") {
deleteData(session, placeUrl);
const placeUrlPublic = basicUrl.concat("/public", "/Places", "/" + placeToDelete.id + ".json");
deleteData(session, placeUrlPublic);
}else {
deleteData(session, placeUrl);
}
// if (placeToDelete.privacy === "Public") {
// deleteData(session, placeUrl);
// const placeUrlPublic = basicUrl.concat("/public", "/Places", "/" + placeToDelete.id + ".json");
// deleteData(session, placeUrlPublic);
// }else {
// deleteData(session, placeUrl);
// }
deleteData(session, placeUrl);
}
}

Expand Down Expand Up @@ -157,19 +148,14 @@ export async function getFriends(webId){
myDataset = await solid.getSolidDataset(friendsURL[i]); // obtain the dataset from the URI
theThing = await solid.getThing(myDataset, friendsURL[i]);

//
let name = solid.getStringNoLocale(theThing, FOAF.name);
// let hasPhoto = theThing.get(getNamedNode(VCARD.hasPhoto));
// let profilePicture = hasPhoto ? solid.getUrl(hasPhoto) : null;

let friend = {
friendURL:friendsURL[i],
friendName:name,
profilePicture:VCARD.hasPhoto.iri.value,
//profilePicture: profilePicture,
//profilePicture: getFriendsImage(friendsURL[i]),
}
//console.log(friend.profilePicture);
}

friends.push(friend);
}
return friends;
Expand All @@ -194,6 +180,88 @@ export async function deleteFriendPod(userWebId, friendwebID) {
await solid.removeUrl(myDataset, FOAF.knows, friendwebID);
await solid.saveSolidDatasetAt(userWebId, myDataset);
}

}
//Función que da permiso a un amigo sobre un sitio
export async function giveFriendPermissionPoint(webId,session, placeId, friendUrl) {

let friendsURL = solid.getUrlAll(await getProfile(webId), FOAF.knows); //array de amigos del usuario

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 }
);

//recorremos el array de amigos para encontrar el amigo con el que queremos compartir el sitio
for(let friend in friendsURL) {
if(friend === friendUrl) {
let resourceAcl = solid.createAcl(file); //recurso de permisos

const updatedAcl = solid.setAgentResourceAccess( //se establecen los permisos
resourceAcl,
friendsURL[friend],
{ read: true, append: false, write: true, control: false }
);
await solid.saveAclFor(file, updatedAcl, { fetch: session.fetch }); //se guardan en el amigo los cambios
console.log("Permisos al amigo :"+ friendsURL);
}

}

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

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

let friendsURL = solid.getUrlAll(await getProfile(webId), FOAF.knows);

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 }
);

//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

const updatedAcl = solid.setAgentResourceAccess( //se establecen los permisos
resourceAcl,
friendsURL[friend],
{ read: true, append: false, write: true, control: false }
);

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

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



export async function getProfile(webId){
let profileDocumentURI = webId.split("#")[0]; // we remove the right hand side of the # for consistency
let myDataset = await solid.getSolidDataset(profileDocumentURI); // obtain the dataset from the URI
return solid.getThing(myDataset, webId); // we obtain the thing we are looking for from the dataset
}

//Devuelve la url para poder acceder al json.ld
export function urlPlaceUser(webId, placeId){
let url = webId.replace("profile/card#me","");
url = url+"private/" + placeId +".json";
return url;
}


0 comments on commit e4a4c19

Please sign in to comment.