Skip to content

Commit b03f21e

Browse files
Sharon's master branch, rebased
1 parent ae5ede8 commit b03f21e

24 files changed

Lines changed: 992 additions & 478 deletions

.prettierrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"htmlWhitespaceSensitivity": "css",
5+
"insertPragma": false,
6+
"jsxBracketSameLine": false,
7+
"jsxSingleQuote": false,
8+
"printWidth": 80,
9+
"proseWrap": "preserve",
10+
"quoteProps": "as-needed",
11+
"requirePragma": false,
12+
"semi": false,
13+
"singleQuote": true,
14+
"tabWidth": 2,
15+
"useTabs": false,
16+
"vueIndentScriptAndStyle": false
17+
}

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Launch Program",
8+
"skipFiles": ["<node_internals>/**"],
9+
"program": "${workspaceFolder}\\lib\\index.js",
10+
"outFiles": ["${workspaceFolder}/**/*.js"]
11+
}
12+
]
13+
}

Documentation/developers/code_README.md

Whitespace-only changes.

Documentation/developers/setup_README.md

Whitespace-only changes.

Documentation/developers/testing_README.md

Whitespace-only changes.

TestTracking.xlsx

8.45 KB
Binary file not shown.

__mocks__/rdflib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ export function Namespace() {
9494
}
9595
export class UpdateManager {
9696
editable() {}
97+
update() {}
9798
}

jest.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
verbose: true,
3+
prettierPath: 'prettier'
4+
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"watch": "npm run build-version && babel src --out-dir lib --watch --source-maps --extensions '.ts,.js'",
1717
"clean": "rm -rf lib",
1818
"coverage": "jest --coverage --collectCoverageFrom=src/**/*.[jt]s",
19-
"lint": "eslint \"src/**/*.js\" \"src/**/*.ts\" \"test/**/*.ts\"",
19+
"lint": "eslint \"src/**/*.js\" \"src/**/*.ts\"",
2020
"lint-fix": "eslint \"src/**/*.js\" \"src/**/*.ts\" --fix",
2121
"jest": "jest",
2222
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --watch",
@@ -51,6 +51,7 @@
5151
"homepage": "https://github.com/solid/solid-ui",
5252
"dependencies": {
5353
"@babel/runtime": "^7.6.2",
54+
"@types/node": "^13.7.0",
5455
"escape-html": "^1.0.3",
5556
"jss": "^10.0.3",
5657
"jss-preset-default": "^10.0.3",
@@ -72,16 +73,14 @@
7273
"@babel/preset-env": "^7.6.2",
7374
"@babel/preset-typescript": "^7.6.0",
7475
"@types/jest": "^25.1.1",
75-
"@types/jsdom": "^12.2.4",
7676
"@types/rdflib": "^0.20.1",
7777
"@typescript-eslint/eslint-plugin": "^2.7.0",
7878
"@typescript-eslint/parser": "^2.6.1",
7979
"eslint": "^6.6.0",
80-
"eslint-plugin-jest": "^23.7.0",
8180
"husky": "^3.0.9",
8281
"jest": "^25.1.0",
83-
"jsdom": "^16.1.0",
8482
"lint-staged": "^10.0.0-1",
83+
"prettier": "^1.19.1",
8584
"standard": "^14.3.1",
8685
"typedoc": "^0.16.9",
8786
"typescript": "^3.6.3"

src/acl/access-groups.ts

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export class AccessGroups {
8585
const groupElements: HTMLElement[] = []
8686
for (let comboIndex = 15; comboIndex > 0; comboIndex--) {
8787
const combo = kToCombo(comboIndex)
88-
if ((this.controller.isEditable && RECOMMENDED[comboIndex]) || this.byCombo[combo]) {
88+
if (
89+
(this.controller.isEditable && RECOMMENDED[comboIndex]) ||
90+
this.byCombo[combo]
91+
) {
8992
groupElements.push(this.renderGroup(comboIndex, combo))
9093
}
9194
}
@@ -95,9 +98,11 @@ export class AccessGroups {
9598
private renderGroup (comboIndex: number, combo: string): HTMLElement {
9699
const groupRow = this.controller.dom.createElement('div')
97100
groupRow.classList.add(this.controller.classes.accessGroupListItem)
98-
widgets.makeDropTarget(groupRow, (uris) => this.handleDroppedUris(uris, combo)
99-
.then(() => this.controller.render())
100-
.catch(error => this.controller.renderStatus(error)))
101+
widgets.makeDropTarget(groupRow, uris =>
102+
this.handleDroppedUris(uris, combo)
103+
.then(() => this.controller.render())
104+
.catch(error => this.controller.renderStatus(error))
105+
)
101106
const groupColumns = this.renderGroupElements(comboIndex, combo)
102107
groupColumns.forEach(column => groupRow.appendChild(column))
103108
return groupRow
@@ -106,38 +111,62 @@ export class AccessGroups {
106111
private renderGroupElements (comboIndex, combo): HTMLElement[] {
107112
const groupNameColumn = this.controller.dom.createElement('div')
108113
groupNameColumn.classList.add(this.controller.classes.group)
109-
groupNameColumn.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
114+
groupNameColumn.classList.toggle(
115+
this.controller.classes[`group-${comboIndex}`],
116+
this.controller.isEditable
117+
)
110118
groupNameColumn.innerText = COLLOQUIAL[comboIndex] || ktToList(comboIndex)
111119

112120
const groupAgentsColumn = this.controller.dom.createElement('div')
113121
groupAgentsColumn.classList.add(this.controller.classes.group)
114-
groupAgentsColumn.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
115-
const groupAgentsTable = groupAgentsColumn.appendChild(this.controller.dom.createElement('table'))
122+
groupAgentsColumn.classList.toggle(
123+
this.controller.classes[`group-${comboIndex}`],
124+
this.controller.isEditable
125+
)
126+
const groupAgentsTable = groupAgentsColumn.appendChild(
127+
this.controller.dom.createElement('table')
128+
)
116129
const combos = this.byCombo[combo] || []
117130
combos
118-
.map(([pred, obj]) => this.renderAgent(groupAgentsTable, combo, pred, obj))
131+
.map(([pred, obj]) =>
132+
this.renderAgent(groupAgentsTable, combo, pred, obj)
133+
)
119134
.forEach(agentElement => groupAgentsTable.appendChild(agentElement))
120135

121136
const groupDescriptionElement = this.controller.dom.createElement('div')
122137
groupDescriptionElement.classList.add(this.controller.classes.group)
123-
groupDescriptionElement.classList.toggle(this.controller.classes[`group-${comboIndex}`], this.controller.isEditable)
124-
groupDescriptionElement.innerText = EXPLANATION[comboIndex] || 'Unusual combination'
138+
groupDescriptionElement.classList.toggle(
139+
this.controller.classes[`group-${comboIndex}`],
140+
this.controller.isEditable
141+
)
142+
groupDescriptionElement.innerText =
143+
EXPLANATION[comboIndex] || 'Unusual combination'
125144

126145
return [groupNameColumn, groupAgentsColumn, groupDescriptionElement]
127146
}
128147

129148
private renderAgent (groupAgentsTable, combo, pred, obj): HTMLElement {
130-
const personRow = widgets.personTR(this.controller.dom, ACL(pred), sym(obj), this.controller.isEditable ? {
131-
deleteFunction: () => this.deleteAgent(combo, pred, obj)
132-
.then(() => groupAgentsTable.removeChild(personRow))
133-
.catch(error => this.controller.renderStatus(error))
134-
} : {})
149+
const personRow = widgets.personTR(
150+
this.controller.dom,
151+
ACL(pred),
152+
sym(obj),
153+
this.controller.isEditable
154+
? {
155+
deleteFunction: () =>
156+
this.deleteAgent(combo, pred, obj)
157+
.then(() => groupAgentsTable.removeChild(personRow))
158+
.catch(error => this.controller.renderStatus(error))
159+
}
160+
: {}
161+
)
135162
return personRow
136163
}
137164

138165
private async deleteAgent (combo, pred, obj): Promise<void> {
139166
const combos = this.byCombo[combo] || []
140-
const comboToRemove = combos.find(([comboPred, comboObj]) => comboPred === pred && comboObj === obj)
167+
const comboToRemove = combos.find(
168+
([comboPred, comboObj]) => comboPred === pred && comboObj === obj
169+
)
141170
if (comboToRemove) {
142171
combos.splice(combos.indexOf(comboToRemove), 1)
143172
}
@@ -149,7 +178,10 @@ export class AccessGroups {
149178
await this.controller.save()
150179
}
151180

152-
private async handleDroppedUris (uris: string[], combo: string): Promise<void> {
181+
private async handleDroppedUris (
182+
uris: string[],
183+
combo: string
184+
): Promise<void> {
153185
try {
154186
await Promise.all(uris.map(uri => this.handleDroppedUri(uri, combo)))
155187
await this.controller.save()
@@ -158,7 +190,11 @@ export class AccessGroups {
158190
}
159191
}
160192

161-
private async handleDroppedUri (uri: string, combo: string, secondAttempt: boolean = false): Promise<void> {
193+
private async handleDroppedUri (
194+
uri: string,
195+
combo: string,
196+
secondAttempt: boolean = false
197+
): Promise<void> {
162198
const agent = findAgent(uri, this.store) // eg 'agent', 'origin', agentClass'
163199
const thing = sym(uri)
164200
if (!agent && !secondAttempt) {
@@ -179,7 +215,12 @@ export class AccessGroups {
179215
this.setACLCombo(combo, uri, agent, this.controller.subject)
180216
}
181217

182-
private setACLCombo (combo: string, uri: string, res: PartialAgentTriple, subject: NamedNode): void {
218+
private setACLCombo (
219+
combo: string,
220+
uri: string,
221+
res: PartialAgentTriple,
222+
subject: NamedNode
223+
): void {
183224
if (!(combo in this.byCombo)) {
184225
this.byCombo[combo] = []
185226
}
@@ -224,7 +265,26 @@ function ktToList (k: number): string {
224265
}
225266
return list
226267
}
227-
268+
function isOriginWithSlashes (uri) {
269+
return (
270+
uri.startsWith('http') && uri.split('/').length === 4 && uri.endsWith('/')
271+
)
272+
}
273+
function isAgentClass (obj) {
274+
return (
275+
obj.sameTerm(ns.foaf('Agent')) ||
276+
obj.sameTerm(ns.acl('AuthenticatedAgent')) || // AuthenticatedAgent
277+
obj.sameTerm(ns.rdf('Resource')) ||
278+
obj.sameTerm(ns.owl('Thing'))
279+
)
280+
}
281+
function isAgent (ns, types) {
282+
return (
283+
ns.vcard('Individual').uri in types ||
284+
ns.foaf('Person').uri in types ||
285+
ns.foaf('Agent').uri in types
286+
)
287+
}
228288
function findAgent (uri, kb): PartialAgentTriple | null {
229289
const obj = sym(uri)
230290
const types = kb.findTypeURIs(obj)
@@ -237,11 +297,7 @@ function findAgent (uri, kb): PartialAgentTriple | null {
237297
return { pred: 'origin', obj: obj } // The only way to know an origin alas
238298
}
239299
// @@ This is an almighty kludge needed because drag and drop adds extra slashes to origins
240-
if (
241-
uri.startsWith('http') &&
242-
uri.split('/').length === 4 &&
243-
uri.endsWith('/')
244-
) {
300+
if (isOriginWithSlashes(uri)) {
245301
// there IS third slash
246302
console.log('Assuming final slash on dragged origin URI was unintended!')
247303
return { pred: 'origin', obj: sym(uri.slice(0, -1)) } // Fix a URI where the drag and drop system has added a spurious slash
@@ -252,19 +308,10 @@ function findAgent (uri, kb): PartialAgentTriple | null {
252308
if (ns.vcard('Group').uri in types) {
253309
return { pred: 'agentGroup', obj: obj } // @@ note vcard membership not RDFs
254310
}
255-
if (
256-
obj.sameTerm(ns.foaf('Agent')) ||
257-
obj.sameTerm(ns.acl('AuthenticatedAgent')) || // AuthenticatedAgent
258-
obj.sameTerm(ns.rdf('Resource')) ||
259-
obj.sameTerm(ns.owl('Thing'))
260-
) {
311+
if (isAgentClass(obj)) {
261312
return { pred: 'agentClass', obj: obj }
262313
}
263-
if (
264-
ns.vcard('Individual').uri in types ||
265-
ns.foaf('Person').uri in types ||
266-
ns.foaf('Agent').uri in types
267-
) {
314+
if (isAgent(ns, types)) {
268315
const pref = kb.any(obj, ns.foaf('preferredURI'))
269316
if (pref) return { pred: 'agent', obj: sym(pref) }
270317
return { pred: 'agent', obj: obj }

0 commit comments

Comments
 (0)