Skip to content

Commit

Permalink
origin -> scope
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Feb 19, 2018
1 parent 219a551 commit 930bf98
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 64 deletions.
20 changes: 10 additions & 10 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,22 @@
"description": "Message displayed when no permissions have been granted (page_proxyAcl_no_perms)"
},
"page_proxyAcl_confirm_revoke": {
"message": "Revoke permission $PERMISSION$ for $ORIGIN$?",
"description": "Confirmation message for revoking a permission for an origin (page_proxyAcl_confirm_revoke)",
"message": "Revoke permission $PERMISSION$ for $SCOPE$?",
"description": "Confirmation message for revoking a permission for a scope (page_proxyAcl_confirm_revoke)",
"placeholders": {
"permission": {
"content": "$1"
},
"origin": {
"scope": {
"content": "$2"
}
}
},
"page_proxyAcl_confirm_revoke_all": {
"message": "Revoke all permissions for $ORIGIN$?",
"description": "Confirmation message for revoking all permissions for an origin (page_proxyAcl_confirm_revoke_all)",
"message": "Revoke all permissions for $SCOPE$?",
"description": "Confirmation message for revoking all permissions for an scope (page_proxyAcl_confirm_revoke_all)",
"placeholders": {
"origin": {
"scope": {
"content": "$1"
}
}
Expand Down Expand Up @@ -401,10 +401,10 @@
}
},
"page_proxyAccessDialog_title": {
"message": "Allow $ORIGIN$ to access ipfs.$PERMISSION$?",
"message": "Allow $SCOPE$ to access ipfs.$PERMISSION$?",
"description": "Main title of the access permission dialog (page_proxyAccessDialog_title)",
"placeholders": {
"origin": {
"scope": {
"content": "$1"
},
"permission": {
Expand All @@ -413,10 +413,10 @@
}
},
"page_proxyAccessDialog_wildcardCheckbox_label": {
"message": "Apply to all permissions for $ORIGIN$",
"message": "Apply to all permissions for $SCOPE$",
"description": "Label for the apply permissions to all checkbox (page_proxyAccessDialog_wildcardCheckbox_label)",
"placeholders": {
"origin": {
"scope": {
"content": "$1"
}
}
Expand Down
16 changes: 8 additions & 8 deletions add-on/src/lib/ipfs-proxy/request-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DIALOG_PATH = 'dist/pages/proxy-access-dialog/index.html'
const DIALOG_PORT_NAME = 'proxy-access-dialog'

function createRequestAccess (browser, screen) {
return async function requestAccess (origin, permission, opts) {
return async function requestAccess (scope, permission, opts) {
opts = opts || {}

const width = opts.dialogWidth || DIALOG_WIDTH
Expand All @@ -21,9 +21,9 @@ function createRequestAccess (browser, screen) {
const { tabs } = await browser.windows.create({ url, width, height, top, left, type: 'popup' })

// Resolves with { allow, wildcard }
const userResponse = getUserResponse(tabs[0].id, origin, permission, opts)
const userResponse = getUserResponse(tabs[0].id, scope, permission, opts)
// Never resolves, might reject if user closes the tab
const userTabRemoved = getUserTabRemoved(tabs[0].id, origin, permission)
const userTabRemoved = getUserTabRemoved(tabs[0].id, scope, permission)

let response

Expand All @@ -40,7 +40,7 @@ function createRequestAccess (browser, screen) {
return response
}

function getUserResponse (tabId, origin, permission, opts) {
function getUserResponse (tabId, scope, permission, opts) {
opts = opts || {}

const dialogPortName = opts.dialogPortName || DIALOG_PORT_NAME
Expand All @@ -52,8 +52,8 @@ function createRequestAccess (browser, screen) {

browser.runtime.onConnect.removeListener(onPortConnect)

// Tell the dialog what origin/permission it is about
port.postMessage({ origin, permission })
// Tell the dialog what scope/permission it is about
port.postMessage({ scope, permission })

// Wait for the user response
const onMessage = ({ allow, wildcard }) => {
Expand All @@ -75,11 +75,11 @@ function createRequestAccess (browser, screen) {
// Since the dialog is a tab not a real dialog it can be closed by the user
// with no response, this function creates a promise that will reject if the tab
// is removed.
function getUserTabRemoved (tabId, origin, permission) {
function getUserTabRemoved (tabId, scope, permission) {
let onTabRemoved

const userTabRemoved = new Promise((resolve, reject) => {
onTabRemoved = () => reject(new Error(`Failed to obtain access response for ${permission} at ${origin}`))
onTabRemoved = () => reject(new Error(`Failed to obtain access response for ${permission} at ${scope}`))
browser.tabs.onRemoved.addListener(onTabRemoved)
})

Expand Down
6 changes: 3 additions & 3 deletions add-on/src/pages/proxy-access-dialog/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ function createProxyAccessDialogPage (i18n) {
const onDeny = () => emit('deny')
const onWildcardToggle = () => emit('wildcardToggle')

const { loading, origin, permission } = state
const { loading, scope, permission } = state

return html`
<div class="flex flex-column pa3 h-100">
<div class="flex-auto">
${loading ? null : html`
<div>
<h1 class="sans-serif f5 lh-copy charcoal mt0">
${i18n.getMessage('page_proxyAccessDialog_title', [origin, permission])}
${i18n.getMessage('page_proxyAccessDialog_title', [scope, permission])}
</h1>
<p class="sans-serif f6 lh-copy charcoal-muted">
<label>
<input type="checkbox" checked=${state.wildcard} onclick=${onWildcardToggle} class="mr1" />
${i18n.getMessage('page_proxyAccessDialog_wildcardCheckbox_label', origin)}
${i18n.getMessage('page_proxyAccessDialog_wildcardCheckbox_label', scope)}
</label>
</p>
</div>
Expand Down
6 changes: 3 additions & 3 deletions add-on/src/pages/proxy-access-dialog/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

function createProxyAccessDialogStore (i18n, runtime) {
return function proxyAccessDialogStore (state, emitter) {
state.origin = null
state.scope = null
state.permission = null
state.loading = true
state.wildcard = false

const port = runtime.connect({ name: 'proxy-access-dialog' })

const onMessage = (data) => {
if (!data || !data.origin || !data.permission) return
if (!data || !data.scope || !data.permission) return
port.onMessage.removeListener(onMessage)

state.origin = data.origin
state.scope = data.scope
state.permission = data.permission
state.loading = false

Expand Down
28 changes: 14 additions & 14 deletions add-on/src/pages/proxy-acl/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function createProxyAclPage (i18n) {
const onToggleAllow = (e) => emit('toggleAllow', e)

const { acl } = state
const origins = Array.from(state.acl.keys())
const hasGrants = origins.some((origin) => !!acl.get(origin).size)
const scopes = Array.from(state.acl.keys())
const hasGrants = scopes.some((scope) => !!acl.get(scope).size)

return html`
<div class="avenir pt5" style="background: linear-gradient(to top, #041727 0%,#043b55 100%); min-height:100%;">
Expand All @@ -32,16 +32,16 @@ function createProxyAclPage (i18n) {
</header>
${hasGrants ? html`
<table class="w-100 mb4" style="border-spacing: 0">
${origins.reduce((rows, origin) => {
const permissions = acl.get(origin)
${scopes.reduce((rows, scope) => {
const permissions = acl.get(scope)
if (!permissions.size) return rows
return rows.concat(
originRow({ onRevoke, origin, i18n }),
scopeRow({ onRevoke, scope, i18n }),
Array.from(permissions.keys())
.sort()
.map((permission) => accessRow({ origin, permission, allow: permissions.get(permission), onRevoke, onToggleAllow, i18n }))
.map((permission) => accessRow({ scope, permission, allow: permissions.get(permission), onRevoke, onToggleAllow, i18n }))
)
}, [])}
</table>
Expand All @@ -56,16 +56,16 @@ function createProxyAclPage (i18n) {

module.exports = createProxyAclPage

function originRow ({ origin, onRevoke, i18n }) {
function scopeRow ({ scope, onRevoke, i18n }) {
return html`
<tr class="">
<th class="f3 normal tl light-gray pv3 ph2 bb b--white-40" colspan="2">${origin}</th>
<th class="tr pv3 ph0 bb b--white-40">${revokeButton({ onRevoke, origin, i18n })}</th>
<th class="f3 normal tl light-gray pv3 ph2 bb b--white-40" colspan="2">${scope}</th>
<th class="tr pv3 ph0 bb b--white-40">${revokeButton({ onRevoke, scope, i18n })}</th>
</tr>
`
}

function accessRow ({ origin, permission, allow, onRevoke, onToggleAllow, i18n }) {
function accessRow ({ scope, permission, allow, onRevoke, onToggleAllow, i18n }) {
const title = i18n.getMessage(
allow
? 'page_proxyAcl_toggle_to_deny_button_title'
Expand All @@ -78,7 +78,7 @@ function accessRow ({ origin, permission, allow, onRevoke, onToggleAllow, i18n }
class="f5 white ph3 pv2 ${allow ? 'bg-green' : 'bg-red'} tc bb b--white-10 pointer"
style="width: 75px"
onclick=${onToggleAllow}
data-origin="${origin}"
data-scope="${scope}"
data-permission="${permission}"
data-allow=${allow}
title="${title}">
Expand All @@ -89,14 +89,14 @@ function accessRow ({ origin, permission, allow, onRevoke, onToggleAllow, i18n }
<td class="f5 light-gray ph3 pv2 bb b--white-10">${permission}</td>
<td class="tr bb b--white-10">
<div class="child">
${revokeButton({ onRevoke, origin, permission, i18n })}
${revokeButton({ onRevoke, scope, permission, i18n })}
</div>
</td>
</tr>
`
}

function revokeButton ({ onRevoke, origin, permission = null, i18n }) {
function revokeButton ({ onRevoke, scope, permission = null, i18n }) {
const title = permission
? i18n.getMessage('page_proxyAcl_revoke_button_title', permission)
: i18n.getMessage('page_proxyAcl_revoke_all_button_title')
Expand All @@ -105,7 +105,7 @@ function revokeButton ({ onRevoke, origin, permission = null, i18n }) {
<button
class="button-reset outline-0 bg-transparent bw0 pointer ph3 pv1 light-gray hover-red"
onclick=${onRevoke}
data-origin="${origin}"
data-scope="${scope}"
data-permission="${permission || ''}"
title="${title}">
${closeIcon()}
Expand Down
12 changes: 6 additions & 6 deletions add-on/src/pages/proxy-acl/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ function createProxyAclStore (accessControl, i18n, confirm = window.confirm) {
})

emitter.on('revoke', (e) => {
const origin = e.currentTarget.getAttribute('data-origin')
const scope = e.currentTarget.getAttribute('data-scope')
const permission = e.currentTarget.getAttribute('data-permission')

const msg = permission
? i18n.getMessage('page_proxyAcl_confirm_revoke', [permission, origin])
: i18n.getMessage('page_proxyAcl_confirm_revoke_all', origin)
? i18n.getMessage('page_proxyAcl_confirm_revoke', [permission, scope])
: i18n.getMessage('page_proxyAcl_confirm_revoke_all', scope)

if (!confirm(msg)) return

accessControl.revokeAccess(origin, permission)
accessControl.revokeAccess(scope, permission)
})

emitter.on('toggleAllow', (e) => {
const origin = e.currentTarget.getAttribute('data-origin')
const scope = e.currentTarget.getAttribute('data-scope')
const permission = e.currentTarget.getAttribute('data-permission')
const allow = e.currentTarget.getAttribute('data-allow') === 'true'
accessControl.setAccess(origin, permission, !allow)
accessControl.setAccess(scope, permission, !allow)
})

async function onAclChange (changes) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/lib/ipfs-proxy/access-control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('lib/ipfs-proxy/access-control', () => {
let error

try {
await accessControl.setAccess('NOT A VALID ORIGIN', 'ipfs.files.add', true)
await accessControl.setAccess('NOT A VALID SCOPE', 'ipfs.files.add', true)
} catch (err) {
error = err
}
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('lib/ipfs-proxy/access-control', () => {
let error

try {
await accessControl.revokeAccess('NOT A VALID ORIGIN', 'ipfs.files.add')
await accessControl.revokeAccess('NOT A VALID SCOPE', 'ipfs.files.add')
} catch (err) {
error = err
}
Expand Down
6 changes: 3 additions & 3 deletions test/functional/pages/proxy-access-dialog/page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const createMockI18n = require('../../../helpers/mock-i18n')
describe('pages/proxy-access-dialog/page', () => {
it('should display title, wildcard checkbox and allow/deny buttons', async () => {
const i18n = createMockI18n()
const state = { origin: 'http://ipfs.io', permission: 'files.add' }
const state = { scope: 'http://ipfs.io', permission: 'files.add' }

let res

expect(() => { res = createProxyAccessDialogPage(i18n)(state).toString() }).to.not.throw()
expect(res).to.have.string(`page_proxyAccessDialog_title[${state.origin},${state.permission}]`)
expect(res).to.have.string(`page_proxyAccessDialog_wildcardCheckbox_label[${state.origin}]`)
expect(res).to.have.string(`page_proxyAccessDialog_title[${state.scope},${state.permission}]`)
expect(res).to.have.string(`page_proxyAccessDialog_wildcardCheckbox_label[${state.scope}]`)
expect(res).to.have.string(`page_proxyAccessDialog_denyButton_text`)
expect(res).to.have.string(`page_proxyAccessDialog_allowButton_text`)
})
Expand Down
22 changes: 11 additions & 11 deletions test/functional/pages/proxy-acl/page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe('pages/proxy-acl/page', () => {
expect(res.toString()).to.have.string('page_proxyAcl_no_perms')
})

it('should render with single origin ACL and single allowed permission', async () => {
it('should render with single scope ACL and single allowed permission', async () => {
const i18n = createMockI18n()
const state = {
acl: objToAcl({
'https://ipfs.io': {
'https://ipfs.io/': {
'ipfs.files.add': true
}
})
Expand All @@ -35,11 +35,11 @@ describe('pages/proxy-acl/page', () => {
expect(res).to.have.string('ipfs.files.add')
})

it('should render with single origin ACL and single denied permission', async () => {
it('should render with single scope ACL and single denied permission', async () => {
const i18n = createMockI18n()
const state = {
acl: objToAcl({
'https://ipfs.io': {
'https://ipfs.io/': {
'ipfs.files.add': false
}
})
Expand All @@ -54,11 +54,11 @@ describe('pages/proxy-acl/page', () => {
expect(res).to.have.string('ipfs.files.add')
})

it('should render with single origin ACL and multiple permissions', async () => {
it('should render with single scope ACL and multiple permissions', async () => {
const i18n = createMockI18n()
const state = {
acl: objToAcl({
'https://ipfs.io': {
'https://ipfs.io/': {
'ipfs.files.add': true,
'ipfs.object.new': false
}
Expand All @@ -76,15 +76,15 @@ describe('pages/proxy-acl/page', () => {
expect(res).to.have.string('ipfs.object.new')
})

it('should render with multiple origins and multiple permissions', async () => {
it('should render with multiple scopes and multiple permissions', async () => {
const i18n = createMockI18n()
const state = {
acl: objToAcl({
'https://ipfs.io': {
'https://ipfs.io/': {
'ipfs.files.add': false,
'ipfs.object.new': true
},
'https://ipld.io': {
'https://ipld.io/': {
'ipfs.block.put': true
}
})
Expand All @@ -94,8 +94,8 @@ describe('pages/proxy-acl/page', () => {

expect(() => { res = createProxyAclPage(i18n)(state).toString() }).to.not.throw()

expect(res).to.have.string('https://ipfs.io')
expect(res).to.have.string('https://ipld.io')
expect(res).to.have.string('https://ipfs.io/')
expect(res).to.have.string('https://ipld.io/')
expect(res).to.have.string('page_proxyAcl_toggle_to_allow_button_title')
expect(res).to.have.string('page_proxyAcl_toggle_to_deny_button_title')
expect(res).to.have.string('ipfs.files.add')
Expand Down
Loading

0 comments on commit 930bf98

Please sign in to comment.