Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Add the ability to set tags in create/forkDrive when prompt=false (#1864
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pfrazee committed Dec 7, 2020
1 parent 7537c71 commit 945b871
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/bg/web-apis/bg/hyperdrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ export default {
if (!res || !res.url) throw new UserDeniedError()
newDriveUrl = res.url
} else {
if (tags && typeof tags === 'string') {
tags = tags.split(' ')
} else if (tags && !Array.isArray(tags)) {
tags = undefined
}
tags = tags.filter(v => typeof v === 'string')

// no modal, ask for permission
await assertCreateDrivePermission(this.sender)
await assertCreateDrivePermission(this.sender, {title, tags})

let importFolder = undefined
if (fromGitUrl) {
Expand Down Expand Up @@ -122,8 +129,15 @@ export default {
if (!res || !res.url) throw new UserDeniedError()
newDriveUrl = res.url
} else {
if (tags && typeof tags === 'string') {
tags = tags.split(' ')
} else if (tags && !Array.isArray(tags)) {
tags = undefined
}
tags = tags.filter(v => typeof v === 'string')

// no modal, ask for permission
await assertCreateDrivePermission(this.sender)
await assertCreateDrivePermission(this.sender, {title, tags})

let key = await lookupUrlDriveKey(url)

Expand Down Expand Up @@ -756,14 +770,14 @@ function assertBeakerOnly (sender) {
}
}

async function assertCreateDrivePermission (sender) {
async function assertCreateDrivePermission (sender, opts) {
// beaker: always allowed
if (wcTrust.isWcTrusted(sender)) {
return true
}

// ask the user
let allowed = await permissions.requestPermission('createDrive', sender)
let allowed = await permissions.requestPermission('createDrive', sender, opts)
if (!allowed) {
throw new UserDeniedError()
}
Expand Down
1 change: 1 addition & 0 deletions app/lib/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export function renderPermDesc ({html, bg, url, permId, permParam, permOpts}) {
return html`<span>Download ${permOpts.filename}</span>`

case 'createDrive':
if (permOpts.tags) return `Create a new hyperdrive tagged "${permOpts.tags.join(', ')}"`
if (permOpts.title) return `Create a new hyperdrive, "${permOpts.title}"`
return 'Create a new hyperdrive'

Expand Down

0 comments on commit 945b871

Please sign in to comment.