@@ -81,14 +81,52 @@ export default class UpdateManager {
81
81
return ( uri . slice ( 0 , 4 ) === 'http' )
82
82
}
83
83
84
+ /** Remove from the store HTTP authorization metadata
85
+ * The editble function below relies on copies we have in the store
86
+ * of the results of previous HTTP transactions. Howver, when
87
+ * the user logs in, then that data misrepresents what would happen
88
+ * if the user tried again.
89
+ */
90
+ flagAuthorizationMetadata ( ) {
91
+ const kb = this . store
92
+ const meta = kb . fetcher . appNode
93
+ const requests = kb . statementsMatching ( undefined , this . ns . link ( 'requestedURI' ) , undefined , meta ) . map ( st => st . subject )
94
+ for ( const request of requests ) {
95
+ const response = kb . any ( request , this . ns . link ( 'response' ) , null , meta ) as Quad_Subject
96
+ if ( response !== undefined ) { // ts
97
+ this . store . add ( response , this . ns . link ( 'outOfDate' ) , true as any , meta ) // @@ Boolean is fine - fix types
98
+ }
99
+ }
100
+ }
84
101
102
+ /**
103
+ * Tests whether a file is editable.
104
+ * If the file has a specific annotation that it is machine written,
105
+ * for safety, it is editable (this doesn't actually check for write access)
106
+ * If the file has wac-allow and accept patch headers, those are respected.
107
+ * and local write access is determined by those headers.
108
+ * This async version not only looks at past HTTP requests, it also makes new ones if necessary.
109
+ *
110
+ * @returns The method string SPARQL or DAV or
111
+ * LOCALFILE or false if known, undefined if not known.
112
+ */
113
+ async checkEditable ( uri : string | NamedNode , kb ?: IndexedFormula ) : Promise < string | boolean | undefined > {
114
+ const initial = this . editable ( uri , kb )
115
+ if ( initial !== undefined ) {
116
+ return initial
117
+ }
118
+ await this . store . fetcher . load ( uri )
119
+ const final = this . editable ( uri , kb )
120
+ // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
121
+ return final
122
+ }
85
123
/**
86
124
* Tests whether a file is editable.
87
125
* If the file has a specific annotation that it is machine written,
88
126
* for safety, it is editable (this doesn't actually check for write access)
89
127
* If the file has wac-allow and accept patch headers, those are respected.
90
128
* and local write access is determined by those headers.
91
- * This version only looks at past HTTP requests, does not make new ones.
129
+ * This synchronous version only looks at past HTTP requests, does not make new ones.
92
130
*
93
131
* @returns The method string SPARQL or DAV or
94
132
* LOCALFILE or false if known, undefined if not known.
@@ -103,7 +141,7 @@ export default class UpdateManager {
103
141
uri = termValue ( uri )
104
142
105
143
if ( ! this . isHttpUri ( uri as string ) ) {
106
- if ( kb . holds (
144
+ if ( this . store . holds (
107
145
this . store . rdfFactory . namedNode ( uri ) ,
108
146
this . store . rdfFactory . namedNode ( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' ) ,
109
147
this . store . rdfFactory . namedNode ( 'http://www.w3.org/2007/ont/link#MachineEditableDocument' ) ) ) {
@@ -113,14 +151,21 @@ export default class UpdateManager {
113
151
114
152
var request
115
153
var definitive = false
154
+ const meta = this . store . fetcher . appNode
155
+ // const kb = s
156
+
116
157
// @ts -ignore passes a string to kb.each, which expects a term. Should this work?
117
- var requests = kb . each ( undefined , this . ns . link ( 'requestedURI' ) , docpart ( uri ) )
158
+ var requests = kb . each ( undefined , this . ns . link ( 'requestedURI' ) , docpart ( uri ) , meta )
118
159
var method : string
119
160
for ( var r = 0 ; r < requests . length ; r ++ ) {
120
161
request = requests [ r ]
121
162
if ( request !== undefined ) {
122
- var response = kb . any ( request , this . ns . link ( 'response' ) ) as Quad_Subject
123
- if ( request !== undefined ) {
163
+ const response = kb . any ( request , this . ns . link ( 'response' ) , null , meta ) as Quad_Subject
164
+ if ( response !== undefined ) { // ts
165
+
166
+ const outOfDate = kb . anyJS ( response , this . ns . link ( 'outOfDate' ) , null , meta ) as Quad_Subject
167
+ if ( outOfDate ) continue
168
+
124
169
var wacAllow = kb . anyValue ( response , this . ns . httph ( 'wac-allow' ) )
125
170
if ( wacAllow ) {
126
171
for ( var bit of wacAllow . split ( ',' ) ) {
0 commit comments