-
Notifications
You must be signed in to change notification settings - Fork 0
/
Upload.sol
66 lines (58 loc) · 1.92 KB
/
Upload.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
pragma abicoder v2;
contract Upload {
struct Access {
address user;
bool access; //true or false
}
struct FileInfo {
string url;
string fileType;
string fileName;
}
mapping(address => FileInfo[]) files;
mapping(address => mapping(address => bool)) ownership;
mapping(address => Access[]) accessList;
mapping(address => mapping(address => bool)) previousData;
function add(
address user,
string memory url,
string memory fileType,
string memory fileName
) external {
files[user].push(FileInfo(url, fileType, fileName));
}
function allow(address user) external {
//def
ownership[msg.sender][user] = true;
if (previousData[msg.sender][user]) {
for (uint i = 0; i < accessList[msg.sender].length; i++) {
if (accessList[msg.sender][i].user == user) {
accessList[msg.sender][i].access = true;
}
}
} else {
accessList[msg.sender].push(Access(user, true));
previousData[msg.sender][user] = true;
}
}
function disallow(address user) public {
ownership[msg.sender][user] = false;
for (uint i = 0; i < accessList[msg.sender].length; i++) {
if (accessList[msg.sender][i].user == user) {
accessList[msg.sender][i].access = false;
}
}
}
function display(address user) external view returns (FileInfo[] memory) {
require(
user == msg.sender || ownership[user][msg.sender],
"You don't have access"
);
return files[user];
}
function shareAccess() public view returns (Access[] memory) {
return accessList[msg.sender];
}
}