Skip to content

Commit

Permalink
feat: show diff between old acl and new one in the linker-dapp (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogoldman authored Mar 3, 2023
1 parent 88234b1 commit 691c944
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"@dcl/crypto": "^3.0.1",
"@dcl/ecs-scene-utils": "^1.7.5",
"@dcl/linker-dapp": "^0.7.0",
"@dcl/linker-dapp": "^0.8.0",
"@dcl/mini-comms": "1.0.0",
"@dcl/protocol": "https://sdk-team-cdn.decentraland.org/@dcl/protocol/branch//dcl-protocol-1.0.0-3130782694.commit-94713ab.tgz",
"@dcl/schemas": "^5.14.0",
Expand Down
29 changes: 17 additions & 12 deletions src/commands/world-acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,23 @@ async function grantAcl(args: arg.Result<typeof spec>) {
const targetContent = args['--target-content']!

try {
const data = await fetchAcl(worldName, targetContent)
const newAllowed = [...data.allowed]
const currentData = await fetchAcl(worldName, targetContent)
const newAllowed = [...currentData.allowed]
addresses.forEach((address: EthAddress) => {
if (!newAllowed.includes(address)) {
newAllowed.push(address)
}
})

const newAcl = { ...data, allowed: newAllowed }
if (newAcl.allowed.length === data.allowed.length) {
const newAcl = { ...currentData, allowed: newAllowed }
if (newAcl.allowed.length === currentData.allowed.length) {
console.log(
'No changes made. All the addresses requested to be granted access already have permission.'
)
return
}

await signAndStoreAcl(args, newAcl)
await signAndStoreAcl(args, newAcl, currentData.allowed)
} catch (error) {
process.exit(1)
}
Expand All @@ -221,30 +221,34 @@ async function revokeAcl(args: arg.Result<typeof spec>) {
const targetContent = args['--target-content']!

try {
const data = await fetchAcl(worldName, targetContent)
const newAllowed = [...data.allowed].filter(
const currentData = await fetchAcl(worldName, targetContent)
const newAllowed = [...currentData.allowed].filter(
(address: EthAddress) => !addresses.includes(address)
)

const newAcl = { ...data, allowed: newAllowed }
if (newAcl.allowed.length === data.allowed.length) {
const newAcl = { ...currentData, allowed: newAllowed }
if (newAcl.allowed.length === currentData.allowed.length) {
console.log(
'No changes made. None of the addresses requested to be revoked accessed had permission.'
)
return
}

await signAndStoreAcl(args, newAcl)
await signAndStoreAcl(args, newAcl, currentData.allowed)
} catch (_) {
process.exit(1)
}
}

async function signAndStoreAcl(
args: arg.Result<typeof spec>,
acl: { resource: string; allowed: EthAddress[] }
acl: { resource: string; allowed: EthAddress[] },
oldAllowed: EthAddress[]
) {
const payload = JSON.stringify(acl)
const payload = JSON.stringify({
...acl,
timestamp: new Date().toISOString()
})

const port = args['--port']
const parsedPort = port ? parseInt(port, 10) : void 0
Expand All @@ -254,6 +258,7 @@ async function signAndStoreAcl(
const worldsContentServer = new WorldsContentServer({
worldName: acl.resource,
allowed: acl.allowed,
oldAllowed: oldAllowed,
isHttps: !!args['--https'],
targetContent,
linkerPort
Expand Down
3 changes: 3 additions & 0 deletions src/lib/WorldsContentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EthAddress } from '@dcl/schemas'
export type WorldsContentServerArguments = {
worldName: string
allowed: EthAddress[]
oldAllowed: EthAddress[]
targetContent: string
linkerPort?: number
isHttps?: boolean
Expand All @@ -41,7 +42,9 @@ export class WorldsContentServer extends EventEmitter {
const linker = new WorldsContentServerLinkerAPI({
worldName: this.options.worldName,
allowed: this.options.allowed,
oldAllowed: this.options.oldAllowed,
targetContent: this.options.targetContent,
expiration: 120,
payload
})
events(linker, '*', this.pipeEvents.bind(this))
Expand Down

0 comments on commit 691c944

Please sign in to comment.