Skip to content

Commit 64f5510

Browse files
lookupmap for repository permission (#41)
* lookupmap for repository permission replace hashmap with lookupmap * add devcontainer setup * update near-sdk-rs * migration test * compile and deploy contract in workspaces * handle calling init twice * remove invitation functionality * bos widget for setting repository permission * support access for implicit accounts * npm audit fix * relative URL for webworker * add wasm32 target before testing
1 parent 6cefdd3 commit 64f5510

File tree

14 files changed

+5468
-833
lines changed

14 files changed

+5468
-833
lines changed

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/universal",
3+
"features": {
4+
"ghcr.io/devcontainers/features/rust:1": {},
5+
"ghcr.io/devcontainers/features/node:1": {}
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"rust-lang.rust-analyzer"
11+
]
12+
}
13+
},
14+
"postCreateCommand": ".devcontainer/post-create.sh"
15+
}

.devcontainer/post-create.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
rustup target add wasm32-unknown-unknown

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ jobs:
4545
- name: Rust smart contract for access control
4646
run: |
4747
cd nearcontract
48+
rustup target add wasm32-unknown-unknown
4849
cargo test --package rust-simple-access-control -- --nocapture

nearboswidget/widget.jsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const [repositoryName, setRepositoryName] = useState("");
2+
const [accountId, setAccountId] = useState("");
3+
4+
const permissionmap = {
5+
'none': 0x00,
6+
'owner': 0x01,
7+
'contributor': 0x02,
8+
'reader': 0x04
9+
};
10+
11+
const [permission, setPermission] = useState(permissionmap['owner']);
12+
13+
function createRepository() {
14+
Near.call("wasmgit.near", "set_permission", {
15+
path: repositoryName,
16+
account_id: accountId,
17+
permission: parseInt(''+permission)
18+
},
19+
undefined
20+
, "100000000000000000000000"
21+
);
22+
};
23+
return (
24+
<>
25+
<h3>Set repository permission</h3>
26+
27+
<h6>Repository name</h6>
28+
<input
29+
placeholder="Repository name"
30+
value={repositoryName}
31+
onInput={(e) => setRepositoryName(e.target.value)}
32+
></input>
33+
34+
<h6>Account id</h6>
35+
<input
36+
placeholder="Account id"
37+
value={accountId}
38+
onInput={(e) => setAccountId(e.target.value)}
39+
></input>
40+
<h6>Permission</h6>
41+
<select value={permission} onChange={(e) => setPermission(e.target.value)}>
42+
{
43+
Object.keys(permissionmap).map(permissionName =>
44+
<option value={permissionmap[permissionName]}>{permissionName}</option>
45+
)
46+
}
47+
</select>
48+
<br />
49+
<button onClick={createRepository}>Create</button>
50+
</>
51+
);

0 commit comments

Comments
 (0)