Skip to content

Commit 0869354

Browse files
committed
file owner control
1 parent 03d8e64 commit 0869354

File tree

3 files changed

+160
-26
lines changed

3 files changed

+160
-26
lines changed

rsa-backend/src/main/java/com/example/rsa/service/UserService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public UserService() {
2121
}
2222

2323
private void addInitialUsers() {
24-
User alice = new User(1, "Alice", false, false, false, false, false, false, new BigInteger("0"), new BigInteger("0"));
25-
User bob = new User(2, "Bob", false, false, false, false, false, false, new BigInteger("0"), new BigInteger("0"));
26-
User charlie = new User(3, "Charlie", false, false, false, false, false, false, new BigInteger("0"), new BigInteger("0"));
24+
User alice = new User(1, "Alice", false, false, false, false, false, false, null, null);
25+
User bob = new User(2, "Bob", false, false, false, false, false, false, null, null);
26+
User charlie = new User(3, "Charlie", false, false, false, false, false, false, null, null);
2727

2828
users.add(alice);
2929
users.add(bob);

rsa-frontend/src/routes/components/FileExplorer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import axios from "axios";
33
import {openFile} from "./api/OpenFile";
44
import Endpoints from "../../contants/endpoints";
55

6-
const FileContainer = ({ owner, fileName, size, id }) => (
6+
const FileContainer = ({ owner, recipient ,fileName, size, id }) => (
77
<div key={id} className={"file-container custom-row"} style={{justifyContent:"space-between",alignItems:"center"}}>
88
<div>
9-
<p className={"font-bold"}>{owner === 1 ? "Alice" : owner === 2 ? "Bob" : "Charlie" }</p>
9+
<div style={{display:"flex",alignItems:"end",gap:6}}>
10+
<p className={"font-bold"}>{owner === 1 ? "Alice" : owner === 2 ? "Bob" : "Charlie" }</p>
11+
{recipient !== owner && <p className={"x-small-text"} style={{fontStyle:"italic"}}>{recipient === 1 ? "to Alice" : recipient === 2 ? "to Bob" : "to Charlie" }</p>}
12+
</div>
1013
<p>{fileName}</p>
1114
<p className={"x-small-text"}>{size}</p>
1215
</div>
@@ -109,7 +112,7 @@ const FileExplorer = () => {
109112
{
110113
(files != null && files.length !== 0) ?
111114
files.map((file) => (
112-
<FileContainer key={file.id} owner={file.ownerId} fileName={file.name} size={`${file.size} bayt`} id={file.id} />
115+
<FileContainer key={file.id} owner={file.ownerId} recipient={file.recipientId} fileName={file.name} size={`${file.size} bayt`} id={file.id} />
113116
)) : <div style={{color:"white",textAlign:"center",padding:"12px 0",backgroundColor:"black",borderRadius:8,fontSize:14}}>Dosya yüklenmemiş</div>
114117

115118
}

rsa-frontend/src/routes/components/ScenarioArea.js

Lines changed: 151 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { toast } from "react-toastify";
99
const UserContainer = ({ userId }) => {
1010
const [loading, setLoading] = useState(false);
1111
const [user, setUser] = useState(null);
12-
const [isModalOpen, setIsModalOpen] = useState(false);
13-
const [fileList, setFileList] = useState([]);
12+
const [isReadModalOpen, setIsReadModalOpen] = useState(false);
13+
const [isReceiveModalOpen, setIsReceiveModalOpen] = useState(false);
14+
const [readFileList, setReadFileList] = useState([]);
15+
const [recipientId, setRecipientId] = useState(null);
16+
const [isUserSelectModalOpen, setIsUserSelectModalOpen] = useState(false);
1417

1518
const fetchUser = async () => {
1619
setLoading(true);
@@ -43,34 +46,47 @@ const UserContainer = ({ userId }) => {
4346
};
4447

4548

46-
const fetchFiles = async () => {
49+
const fetchReadFiles = async () => {
4750
setLoading(true);
4851
try {
4952
const response = await axios.get(`${Endpoints.FILE}/info/${user.id}`);
50-
setFileList(response.data);
53+
setReadFileList(response.data);
5154
} catch (error) {
5255
console.error("Dosyalar alınırken hata oluştu:", error);
5356
}
5457
setLoading(false);
5558
};
5659

57-
const openModal = () => {
58-
setIsModalOpen(true);
59-
fetchFiles();
60+
const openReadModal = () => {
61+
setIsReadModalOpen(true);
62+
fetchReadFiles();
6063
};
6164

62-
const closeModal = () => {
63-
setIsModalOpen(false);
65+
const closeReadModal = () => {
66+
setIsReadModalOpen(false);
67+
};
68+
69+
const openReceiveModal = () => {
70+
setIsReceiveModalOpen(true);
71+
};
72+
73+
const closeReceiveModal = () => {
74+
setIsReceiveModalOpen(false);
75+
};
76+
77+
const openUserSelectModal = () => setIsUserSelectModalOpen(true);
78+
const closeUserSelectModal = () => {
79+
setIsUserSelectModalOpen(false);
80+
setRecipientId(null);
6481
};
6582

6683

6784
const handleFileChange = (event, userId, recipientId) => {
6885
setLoading(true);
6986
const file = event.target.files[0];
70-
7187
if (file) {
7288
if (file.size > 512) {
73-
toast.error("Dosya boyutu 256 byte'ı geçemez. Lütfen daha küçük bir dosya yükleyin.");
89+
toast.error("Dosya boyutu 512 byte'ı geçemez. Lütfen daha küçük bir dosya yükleyin.");
7490
setLoading(false);
7591
return;
7692
}
@@ -100,6 +116,50 @@ const UserContainer = ({ userId }) => {
100116
setLoading(false);
101117
};
102118

119+
const handleUserSelectForRecipient = (event, userId) => {
120+
setLoading(true);
121+
const file = event.target.files[0];
122+
if (file) {
123+
if (file.size > 512) {
124+
toast.error("Dosya boyutu 512 byte'ı geçemez. Lütfen daha küçük bir dosya yükleyin.");
125+
setLoading(false);
126+
return;
127+
}
128+
129+
if (!recipientId) {
130+
toast.error("Göndereceğiniz kişiyi seçmediniz.");
131+
setLoading(false);
132+
return;
133+
}
134+
135+
const formData = new FormData();
136+
formData.append('file', file);
137+
formData.append('userId', userId);
138+
formData.append('recipientId', recipientId);
139+
140+
axios.post(Endpoints.FILE, formData, {
141+
headers: {
142+
'Content-Type': 'multipart/form-data'
143+
}
144+
}).then(response => {
145+
toast.success("Dosya başarıyla yüklendi");
146+
console.log("Dosya başarıyla yüklendi:", response.data);
147+
closeUserSelectModal();
148+
}).catch(error => {
149+
toast.error("Dosya yüklenemedi");
150+
console.error("Dosya yüklenirken hata oluştu:", error);
151+
});
152+
} else {
153+
toast.error("Dosya seçmediniz");
154+
}
155+
setLoading(false);
156+
};
157+
158+
const handleRecipientSelect = (id) => {
159+
setRecipientId(id);
160+
};
161+
162+
103163
return (
104164
<>
105165
{loading && <div className={"loading-overlay"}><div className={"main-spinner"}></div></div>}
@@ -115,7 +175,7 @@ const UserContainer = ({ userId }) => {
115175
/>
116176
<div>
117177
<p>Açık Anahtar</p>
118-
<p className={"x-small-text font-bold"}>{user.publicKey ? "Hazır" : "Kapalı"}</p>
178+
<p className={"x-small-text font-bold"}>{user.publicKey ? user.EKey === null ? "Bekleniyor" : "Hazır" : "Kapalı"}</p>
119179
</div>
120180
</div>
121181

@@ -127,7 +187,7 @@ const UserContainer = ({ userId }) => {
127187
/>
128188
<div>
129189
<p>Kapalı Anahtar</p>
130-
<p className={"x-small-text font-bold"}>{user.privateKey ? "Hazır" : "Kapalı"}</p>
190+
<p className={"x-small-text font-bold"}>{user.privateKey ? user.Dkey === null ? "Bekleniyor" : "Hazır" : "Kapalı"}</p>
131191
</div>
132192
</div>
133193

@@ -170,23 +230,25 @@ const UserContainer = ({ userId }) => {
170230
<div>
171231
<p>Dosya Okuma</p>
172232
<p className={"x-small-text font-bold"}>{user.fileRead ? "Açık" : "Kapalı"}</p>
173-
<div className={"user-operation-button"} style={{backgroundColor: user.fileRead && "rgb(16,64,59)", cursor: user.fileRead && "pointer",}} onClick={user.fileRead ? openModal : null}>
233+
<div className={"user-operation-button"} style={{backgroundColor: user.fileRead && "rgb(16,64,59)", cursor: user.fileRead && "pointer",}} onClick={user.fileRead ? openReadModal : null}>
174234
Dosya Görüntüle
175235
</div>
176236
</div>
177-
<Modal isOpen={isModalOpen} onRequestClose={closeModal} contentLabel="Dosyalar">
237+
<Modal isOpen={isReadModalOpen} onRequestClose={closeReadModal} contentLabel="Dosyalar">
178238
<div className={"custom-row"} style={{justifyContent:"space-between"}}>
179239
<h2>{`Kullanıcı Dosyaları : ${user.name}`}</h2>
180-
<p onClick={closeModal} style={{cursor:"pointer"}}>Kapat</p>
240+
<p onClick={closeReadModal} style={{cursor:"pointer"}}>Kapat</p>
181241
</div>
182-
<p style={{marginTop:8,marginBottom:16}}>{fileList.length} adet dosya listelendi</p>
242+
<p style={{marginTop:8,marginBottom:16}}>{readFileList.length} adet dosya listelendi</p>
183243
{loading ? (<p>Yükleniyor...</p>) : (
184-
fileList.map((file) => (
185-
<div key={file.id} style={{backgroundColor:"var(--secondary-color-1)",padding:8,borderRadius:8}}>
244+
readFileList.map((file) => (
245+
<div key={file.id} style={{backgroundColor:"var(--secondary-color-1)",padding:8,borderRadius:8,marginBottom:8}}>
186246
<div className={"custom-row"} style={{justifyContent:"space-between",alignItems:"center"}}>
187247
<div>
188248
<p>{file.originalName}</p>
189249
<p className={"x-small-text"}>{file.size} bayt</p>
250+
<p className={"x-small-text"}>{file.recipientId === userId ? "Bu dosyayı kendiniz için yüklediniz" :
251+
<p className={"x-small-text"} style={{fontStyle:"italic"}}>{file.recipientId === 1 ? "Bu dosyayı Alice için yüklediniz" : file.recipientId === 2 ? "Bu dosyayı Bob için yüklediniz" : "Bu dosyayı Charlie için yüklediniz" }</p>}</p>
190252
</div>
191253
<div
192254
className={"icon-box"}
@@ -203,6 +265,75 @@ const UserContainer = ({ userId }) => {
203265

204266
</Modal>
205267
</div>
268+
<div className={"custom-row"} style={{gap:0}}>
269+
<Switch
270+
isOn={user.fileSend}
271+
handleToggle={() => handleToggle('fileSend',!user.fileSend)}
272+
id={user.id+"fileSend"}
273+
/>
274+
<div>
275+
<p>Dosya Gönderme</p>
276+
<p className={"x-small-text font-bold"}>
277+
{user.fileSend ? "Açık" : "Kapalı"}
278+
</p>
279+
<div className={"user-operation-button"}
280+
style={{ backgroundColor: user.fileSend && "rgb(175,191,54)", cursor: user.fileSend && "pointer" }}
281+
onClick={openUserSelectModal}
282+
>
283+
Dosya Gönder
284+
</div>
285+
286+
{isUserSelectModalOpen && (
287+
<Modal isOpen={isUserSelectModalOpen} onRequestClose={closeUserSelectModal} contentLabel="Users">
288+
<div className={"custom-row"} style={{ justifyContent: "space-between" }}>
289+
<h3>Gönderilecek dosyayı ve kime gönderileceğini seçiniz</h3>
290+
<p onClick={closeUserSelectModal} style={{ cursor: "pointer" }}>Kapat</p>
291+
</div>
292+
<div>
293+
{user.name !== "Alice" && (
294+
<p onClick={() => handleRecipientSelect(1)} style={{ color: recipientId === 1 ? "green" : "black" ,padding:8,cursor:"pointer"}}>Alice</p>
295+
)}
296+
{user.name !== "Bob" && (
297+
<p onClick={() => handleRecipientSelect(2)} style={{ color: recipientId === 2 ? "green" : "black" ,padding:8,cursor:"pointer"}}>Bob</p>
298+
)}
299+
{user.name !== "Charlie" && (
300+
<p onClick={() => handleRecipientSelect(3)} style={{ color: recipientId === 3 ? "green" : "black" ,padding:8,cursor:"pointer"}}>Charlie</p>
301+
)}
302+
</div>
303+
{recipientId && (
304+
<input
305+
type="file"
306+
id={`fileSend-${user.id}`}
307+
accept=".txt,.pdf,.doc,.docx"
308+
onChange={(event) => handleUserSelectForRecipient(event, user.id)}
309+
/>
310+
)}
311+
</Modal>
312+
)}
313+
314+
</div>
315+
316+
</div>
317+
<div className={"custom-row"} style={{ gap: 0 }}>
318+
<Switch
319+
isOn={user.fileReceive}
320+
handleToggle={() => handleToggle("fileReceive", !user.fileReceive)}
321+
id={user.id + "fileReceive"}
322+
/>
323+
<div>
324+
<p>Dosya Alma</p>
325+
<p className={"x-small-text font-bold"}>{user.fileReceive ? "Açık" : "Kapalı"}</p>
326+
<div className={"user-operation-button"} style={{backgroundColor: user.fileReceive && "rgb(134,149,11)", cursor: user.fileReceive && "pointer",}} onClick={user.fileReceive ? openReceiveModal : null}>
327+
Dosya Al
328+
</div>
329+
</div>
330+
<Modal isOpen={isReceiveModalOpen} onRequestClose={closeReceiveModal} contentLabel="Dosyalar">
331+
<div className={"custom-row"} style={{justifyContent:"space-between"}}>
332+
<h2>{`${user.name} Kullanıcısına Gelen Dosyalar`}</h2>
333+
<p onClick={closeReceiveModal} style={{cursor:"pointer"}}>Kapat</p>
334+
</div>
335+
</Modal>
336+
</div>
206337
</div>
207338
</div>
208339
))}
@@ -231,7 +362,7 @@ const ScenarioArea = () => {
231362
fetchUser();
232363
console.log(users);
233364
}
234-
}, []);
365+
}, );
235366

236367

237368
const handleUserClick = (userId) => {

0 commit comments

Comments
 (0)