Skip to content

Commit 3ef6750

Browse files
Some fixes
1 parent 8716403 commit 3ef6750

6 files changed

Lines changed: 115 additions & 71 deletions

File tree

src/acl/acl.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { solidLogicSingleton } from '../logic'
1010
import utils from '../utils'
1111
import { AgentMapMap, AgentMapUnion, ComboList } from './types'
1212
import * as debug from '../debug'
13-
import { graph, IndexedFormula, NamedNode, serialize, st, sym } from 'rdflib'
13+
import { graph, IndexedFormula, NamedNode, serialize, st, Statement, sym } from 'rdflib'
1414
import { LiveStore } from 'pane-registry'
1515
import { ACL_LINK } from 'solid-logic'
1616

@@ -36,15 +36,15 @@ export function adoptACLDefault (
3636
.concat(kb.each(undefined, ACL('defaultForNew'), defaultResource, defaultACLDoc))
3737

3838
const proposed = defaults.reduce((accumulatedStatements, da) => accumulatedStatements
39-
.concat(kb.statementsMatching(da, ns.rdf('type'), ACL('Authorization'), defaultACLDoc))
40-
.concat(kb.statementsMatching(da, ACL('agent'), undefined, defaultACLDoc))
41-
.concat(kb.statementsMatching(da, ACL('agentClass'), undefined, defaultACLDoc))
42-
.concat(kb.statementsMatching(da, ACL('agentGroup'), undefined, defaultACLDoc))
43-
.concat(kb.statementsMatching(da, ACL('origin'), undefined, defaultACLDoc))
44-
.concat(kb.statementsMatching(da, ACL('originClass'), undefined, defaultACLDoc))
45-
.concat(kb.statementsMatching(da, ACL('mode'), undefined, defaultACLDoc))
46-
.concat(st(da, ACL('accessTo'), doc, defaultACLDoc))
47-
.concat(isContainer ? st(da, ACL('default'), doc, defaultACLDoc) : []), [])
39+
.concat(kb.statementsMatching(da as NamedNode, ns.rdf('type'), ACL('Authorization'), defaultACLDoc))
40+
.concat(kb.statementsMatching(da as NamedNode, ACL('agent'), undefined, defaultACLDoc))
41+
.concat(kb.statementsMatching(da as NamedNode, ACL('agentClass'), undefined, defaultACLDoc))
42+
.concat(kb.statementsMatching(da as NamedNode, ACL('agentGroup'), undefined, defaultACLDoc))
43+
.concat(kb.statementsMatching(da as NamedNode, ACL('origin'), undefined, defaultACLDoc))
44+
.concat(kb.statementsMatching(da as NamedNode, ACL('originClass'), undefined, defaultACLDoc))
45+
.concat(kb.statementsMatching(da as NamedNode, ACL('mode'), undefined, defaultACLDoc))
46+
.concat(st(da as NamedNode, ACL('accessTo'), doc, defaultACLDoc))
47+
.concat(isContainer ? st(da as NamedNode, ACL('default'), doc, defaultACLDoc) : []), [] as Statement[])
4848

4949
const kb2 = graph() // Potential - derived is kept apart
5050
proposed.forEach(st => kb2.add(move(st.subject), move(st.predicate), move(st.object), sym(aclDoc.uri)))
@@ -355,7 +355,7 @@ type fixIndividualACLCallback = (ok: boolean, message?: string | NamedNode | Age
355355
* All group files must be loaded first
356356
*/
357357
export function fixIndividualCardACL (person: NamedNode, log: Function, callbackFunction: fixIndividualCardACLCallback): void {
358-
const groups = kb.each(undefined, ns.vcard('hasMember'), person)
358+
const groups = kb.each(undefined, ns.vcard('hasMember'), person) as NamedNode[]
359359
// const doc = person.doc()
360360
if (groups) {
361361
fixIndividualACL(person, groups, log, callbackFunction)
@@ -396,7 +396,7 @@ export function fixIndividualACL (item: NamedNode, subjects: Array<NamedNode>, l
396396
// makeACLString(targetDoc, ac, targetACLDoc))
397397

398398
putACLObject(
399-
kb,
399+
kb as unknown as LiveStore,
400400
targetDoc as NamedNode,
401401
union as AgentMapMap | AgentMapUnion,
402402
targetACLDoc as NamedNode,
@@ -416,34 +416,44 @@ export function setACL (
416416
callbackFunction: (ok: boolean, message: string) => void
417417
): void {
418418
const aclDoc = kb.any(
419-
kb.sym(docURI),
420-
kb.sym(ACL_LINK)
419+
docURI,
420+
ACL_LINK
421421
) // @@ check that this get set by web.js
422+
if (!kb.fetcher) {
423+
throw new Error('Store has no fetcher')
424+
}
422425
if (aclDoc) {
423426
// Great we already know where it is
424427
kb.fetcher
425-
.webOperation('PUT', aclDoc.uri, {
428+
.webOperation('PUT', aclDoc.value, {
426429
data: aclText,
427430
contentType: 'text/turtle'
428431
})
429-
.then(callbackFunction) // @@@ check params
432+
.then((res) => {
433+
callbackFunction(res.ok, res.error || '')
434+
}) // @@@ check params
430435
} else {
431436
kb.fetcher.nowOrWhenFetched(docURI, undefined, function (ok, body) {
432437
if (!ok) return callbackFunction(ok, 'Gettting headers for ACL: ' + body)
433438
const aclDoc = kb.any(
434-
kb.sym(docURI),
435-
kb.sym(ACL_LINK)
439+
docURI,
440+
ACL_LINK
436441
) // @@ check that this get set by web.js
437442
if (!aclDoc) {
438443
// complainIfBad(false, "No Link rel=ACL header for " + docURI)
439444
callbackFunction(false, 'No Link rel=ACL header for ' + docURI)
440445
} else {
446+
if (!kb.fetcher) {
447+
throw new Error('Store has no fetcher')
448+
}
441449
kb.fetcher
442-
.webOperation('PUT', aclDoc.uri, {
450+
.webOperation('PUT', aclDoc.value, {
443451
data: aclText,
444452
contentType: 'text/turtle'
445453
})
446-
.then(callbackFunction)
454+
.then((res) => {
455+
callbackFunction(res.ok, res.error || '')
456+
})
447457
}
448458
})
449459
}
@@ -469,7 +479,7 @@ export function getACLorDefault (
469479
d?: NamedNode
470480
) => void
471481
): void {
472-
getACL(doc, function (ok, status, aclDoc, message) {
482+
getACL(doc, function (ok, status, aclDoc, message): string | void {
473483
const ACL = ns.acl
474484
if (!ok) return callbackFunction(false, false, status as number, message as string)
475485

@@ -485,14 +495,14 @@ export function getACLorDefault (
485495
}
486496
uri = uri.slice(0, right + 1)
487497
const doc2 = sym(uri)
488-
getACL(doc2, function (ok, status, defaultACLDoc) {
498+
getACL(doc2, function (ok, status, defaultACLDoc: any): NamedNode | void {
489499
if (!ok) {
490500
return callbackFunction(
491501
false,
492502
true,
493503
status as number,
494504
`( No ACL pointer ${uri} ${status})${defaultACLDoc}`
495-
)
505+
) as void
496506
} else if (status === 403) {
497507
return callbackFunction(
498508
false,
@@ -579,26 +589,32 @@ export function getACL (
579589
message?: string
580590
) => void
581591
): void {
592+
if (!kb.fetcher) {
593+
throw new Error('kb has no fetcher')
594+
}
582595
kb.fetcher.nowOrWhenFetched(doc, undefined, function (ok, body) {
583596
if (!ok) {
584597
return callbackFunction(ok, `Can't get headers to find ACL for ${doc}: ${body}`)
585598
}
586599
const aclDoc = kb.any(
587600
doc,
588-
kb.sym(ACL_LINK)
601+
ACL_LINK
589602
) // @@ check that this get set by web.js
590603
if (!aclDoc) {
591604
callbackFunction(false, 900, `No Link rel=ACL header for ${doc}`)
592605
} else {
593-
if (kb.fetcher.nonexistent[aclDoc.uri]) {
606+
if (!kb.fetcher) {
607+
throw new Error('kb has no fetcher')
608+
}
609+
if (kb.fetcher.nonexistent[aclDoc.value]) {
594610
return callbackFunction(
595611
true,
596612
404,
597-
aclDoc,
613+
aclDoc as NamedNode,
598614
`ACL file ${aclDoc} does not exist.`
599615
)
600616
}
601-
kb.fetcher.nowOrWhenFetched(aclDoc, undefined, function (
617+
kb.fetcher.nowOrWhenFetched(aclDoc as NamedNode, undefined, function (
602618
ok,
603619
message,
604620
response
@@ -607,11 +623,11 @@ export function getACL (
607623
callbackFunction(
608624
true,
609625
response.status,
610-
aclDoc,
626+
aclDoc as NamedNode,
611627
`Can't read Access Control File ${aclDoc}: ${message}`
612628
)
613629
} else {
614-
callbackFunction(true, 200, aclDoc)
630+
callbackFunction(true, 200, aclDoc as NamedNode)
615631
}
616632
})
617633
}

src/widgets/buttons.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ export function setName (element: HTMLElement, x: NamedNode) {
186186
const name = x.sameTerm(ns.foaf('Agent')) ? 'Everyone' : findName(x)
187187
element.textContent = name || utils.label(x)
188188
if (!name && x.uri) {
189+
if (!kb.fetcher) {
190+
throw new Error('kb has no fetcher')
191+
}
189192
// Note this is only a fetch, not a lookUP of all sameAs etc
190193
kb.fetcher.nowOrWhenFetched(x.doc(), undefined, function (_ok) {
191194
element.textContent = findName(x) || utils.label(x) // had: (ok ? '' : '? ') +
@@ -335,7 +338,7 @@ export function findImage (thing: NamedNode): string {
335338
kb.any(thing, ns.vcard('hasPhoto')) ||
336339
kb.any(thing, ns.vcard('photo')) ||
337340
kb.any(thing, ns.foaf('depiction'))
338-
return image ? image.uri : null
341+
return image ? (image as any).uri : null
339342
}
340343

341344
/**
@@ -395,6 +398,9 @@ export function setImage (element: HTMLElement, thing: NamedNode) { // 20191230a
395398

396399
const happy = trySetImage(element, thing, iconForClassMap)
397400
if (!happy && thing.uri) {
401+
if (!kb.fetcher) {
402+
throw new Error('kb has no fetcher')
403+
}
398404
kb.fetcher.nowOrWhenFetched(thing.doc(), undefined, (ok) => {
399405
if (ok) {
400406
trySetImage(element, thing, iconForClassMap)
@@ -473,7 +479,7 @@ export function deleteButtonWithCheck (
473479
},
474480
false
475481
)
476-
var sureButtonElt = dom.createElement('button')
482+
const sureButtonElt = dom.createElement('button')
477483
sureButtonElt.textContent = 'Delete ' + noun
478484
sureButtonElt.setAttribute('style', style.buttonStyle)
479485
container.appendChild(sureButtonElt).addEventListener(
@@ -762,7 +768,11 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
762768
attachmentTable.appendChild(dom.createElement('tr')) // attachmentTableTop
763769

764770
const deleteAttachment = function (target) {
765-
kb.updater.update(st(subject, predicate, target, doc), [], function (
771+
if (!kb.updater) {
772+
throw new Error('kb has no updater')
773+
}
774+
775+
kb.updater.update(st(subject, predicate, target, doc) as any, [], function (
766776
uri,
767777
ok,
768778
errorBody,
@@ -785,7 +795,7 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
785795
}
786796
return personTR(dom, predicate, target, opt)
787797
}
788-
var refresh = ((attachmentTable as any).refresh = function () {
798+
const refresh = ((attachmentTable as any).refresh = function () {
789799
const things = kb.each(subject, predicate)
790800
things.sort()
791801
utils.syncTableToArray(attachmentTable, things, createNewRow)
@@ -800,6 +810,10 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
800810
debug.log('Dropped on attachemnt ' + u) // icon was: iconBase + 'noun_25830.svg'
801811
ins.push(st(subject, predicate, target, doc))
802812
})
813+
if (!kb.updater) {
814+
throw new Error('kb has no updater')
815+
}
816+
803817
kb.updater.update([], ins, function (uri, ok, errorBody, _xhr) {
804818
if (ok) {
805819
refresh()
@@ -817,6 +831,9 @@ export function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTML
817831
options.uploadFolder?.uri, // Pictures
818832
function (theFile, destURI) {
819833
const ins = [st(subject, predicate, kb.sym(destURI), doc)]
834+
if (!kb.updater) {
835+
throw new Error('kb has no updater')
836+
}
820837
kb.updater.update([], ins, function (uri, ok, errorBody, _xhr) {
821838
if (ok) {
822839
refresh()
@@ -906,18 +923,18 @@ export function allClassURIs (): { [uri: string]: boolean } {
906923
store
907924
.statementsMatching(undefined, ns.rdf('type'), undefined)
908925
.forEach(function (st) {
909-
if (st.object.uri) set[st.object.uri] = true
926+
if (st.object.value) set[st.object.value] = true
910927
})
911928
store
912929
.statementsMatching(undefined, ns.rdfs('subClassOf'), undefined)
913930
.forEach(function (st) {
914-
if (st.object.uri) set[st.object.uri] = true
915-
if (st.subject.uri) set[st.subject.uri] = true
931+
if (st.object.value) set[st.object.value] = true
932+
if (st.subject.value) set[st.subject.value] = true
916933
})
917934
store
918935
.each(undefined, ns.rdf('type'), ns.rdfs('Class'))
919936
.forEach(function (c) {
920-
if (c.uri) set[c.uri] = true
937+
if (c.value) set[c.value] = true
921938
})
922939
return set
923940
}
@@ -944,7 +961,7 @@ export function propertyTriage (kb: IndexedFormula): any {
944961
let nd = 0
945962
let nu = 0
946963
const pi = (kb as any).predicateIndex // One entry for each pred
947-
for (var p in pi) {
964+
for (const p in pi) {
948965
const object = pi[p][0].object
949966
if (object.termType === 'Literal') {
950967
dp[p] = true
@@ -956,7 +973,7 @@ export function propertyTriage (kb: IndexedFormula): any {
956973
} // If nothing discovered, then could be either:
957974
const ps = kb.each(undefined, ns.rdf('type'), ns.rdf('Property'))
958975
for (let i = 0; i < ps.length; i++) {
959-
p = ps[i].toNT()
976+
const p = ps[i].toNT()
960977
// log.debug('propertyTriage: unknown: ' + p)
961978
if (!op[p] && !dp[p]) {
962979
dp[p] = true
@@ -1095,7 +1112,7 @@ export function selectorPanelRefresh (
10951112
'src',
10961113
options.connectIcon || iconBase + 'noun_25830.svg'
10971114
)
1098-
image.setAttribute('title', already.length ? already.length : 'attach')
1115+
image.setAttribute('title', already.length ? already.length : 'attach' as any)
10991116
}
11001117
const f = index.twoLine.widgetForClass(type)
11011118
// eslint-disable-next-line prefer-const
@@ -1112,7 +1129,7 @@ export function selectorPanelRefresh (
11121129
nav.appendChild(a).textContent = '>'
11131130
box.appendChild(nav)
11141131

1115-
var iconDiv = dom.createElement('div')
1132+
const iconDiv = dom.createElement('div')
11161133
iconDiv.setAttribute(
11171134
'style',
11181135
(inverse ? 'float:left;' : 'float:right;') + ' width:30px;'
@@ -1287,7 +1304,7 @@ export function isImage (file?: NamedNode, kind?: string): boolean {
12871304
const what = kind || 'image'
12881305
// See https://github.com/linkeddata/rdflib.js/blob/e367d5088c/src/formula.ts#L554
12891306
//
1290-
const typeURIs = store.findTypeURIs(file)
1307+
const typeURIs = store.findTypeURIs(file as any)
12911308
// See https://github.com/linkeddata/rdflib.js/blob/d5000f/src/utils-js.js#L14
12921309
// e.g.'http://www.w3.org/ns/iana/media-types/audio'
12931310
const prefix: string = Util.mediaTypeClass(what + '/*').uri.split('*')[0]

src/widgets/forms.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ forms.field[ns.ui('Form').uri] = forms.field[
9999
if (dep && kb.any(subject, dep)) original[i] = kb.any(subject, dep).toNT()
100100
}
101101

102-
var fn = fieldFunction(dom, field)
102+
const fn = fieldFunction(dom, field)
103103

104104
const itemChanged = function (ok, body) {
105105
if (ok) {
@@ -311,7 +311,8 @@ forms.field[ns.ui('Multiple').uri] = function (
311311
async function moveThisItem (event, upwards) {
312312
// @@ possibly, allow shift+click to do move to top or bottom?
313313
debug.log('pre move: ' + debugString(list.elements))
314-
for (var i = 0; i < list.elements.length; i++) {
314+
let i
315+
for (i = 0; i < list.elements.length; i++) {
315316
// Find object in array
316317
if (list.elements[i].sameTerm(object)) {
317318
break
@@ -349,7 +350,7 @@ forms.field[ns.ui('Multiple').uri] = function (
349350
linkDone(uri, ok, message)
350351
}
351352
}
352-
var linkDone = function (uri, ok, message) {
353+
const linkDone = function (uri, ok, message) {
353354
return callbackFunction(ok, message)
354355
}
355356

@@ -360,7 +361,7 @@ forms.field[ns.ui('Multiple').uri] = function (
360361
// var del = []
361362

362363
const fn = fieldFunction(dom, element)
363-
var subField = fn(dom, null, already, object, element, store, itemDone) // p2 was: body. moving to not passing that
364+
const subField = fn(dom, null, already, object, element, store, itemDone) // p2 was: body. moving to not passing that
364365
subField.subject = object // Keep a back pointer between the DOM array and the RDF objects
365366

366367
// delete button and move buttons
@@ -389,7 +390,7 @@ forms.field[ns.ui('Multiple').uri] = function (
389390

390391
const kb = UI.store
391392
kb.updater = kb.updater || new $rdf.UpdateManager(kb)
392-
var box = dom.createElement('table')
393+
const box = dom.createElement('table')
393394
// We don't indent multiple as it is a sort of a prefix of the next field and has contents of one.
394395
// box.setAttribute('style', 'padding-left: 2em; border: 0.05em solid green;') // Indent a multiple
395396
const ui = UI.ns.ui
@@ -398,7 +399,7 @@ forms.field[ns.ui('Multiple').uri] = function (
398399
const orderedNode = kb.any(form, ui('ordered'))
399400
const ordered = orderedNode ? $rdf.Node.toJS(orderedNode) : false
400401

401-
var property = kb.any(form, ui('property'))
402+
const property = kb.any(form, ui('property'))
402403
const reverse = kb.anyJS(form, ui('reverse'))
403404
if (!property) {
404405
box.appendChild(
@@ -1388,7 +1389,7 @@ forms.makeSelectForOptions = function (
13881389
})
13891390
}
13901391

1391-
var select = dom.createElement('select')
1392+
const select = dom.createElement('select')
13921393
select.setAttribute('style', 'margin: 0.6em 1.5em;')
13931394
if (options.multiple) select.setAttribute('multiple', 'true')
13941395
select.currentURI = null

0 commit comments

Comments
 (0)