1- /* Profile Editing Pane
1+ /* Trusted Apps Editing Pane
22**
33** Unlike most panes, this is available any place whatever the real subject,
4- ** and allows the user to edit their own profile .
4+ ** and allows the user to edit their own profil, sepciufically the set of apps they trust .
55**
6- ** Usage: paneRegistry.register('profile/profilePane')
76** or standalone script adding onto existing mashlib.
87*/
98
9+ /* global alert */
1010const nodeMode = ( typeof module !== 'undefined' )
1111var panes , UI
1212
@@ -29,11 +29,11 @@ const thisPane = {
2929 name : 'trustedApplications' ,
3030
3131 label : function ( subject ) {
32- var types = kb . findTypeURIs ( subject )
33- if ( types [ UI . ns . foaf ( 'Person' ) . uri ] || types [ UI . ns . vcard ( 'Individual' ) . uri ] ) {
34- return 'Manage your trusted applications'
35- }
36- return null
32+ // var types = kb.findTypeURIs(subject) // Show aloways like home pane
33+ // if (types[UI.ns.foaf('Person').uri] || types[UI.ns.vcard('Individual').uri]) {
34+ return 'Manage your trusted applications'
35+ // }
36+ // return null
3737 } ,
3838
3939 render : function ( subject , dom ) {
@@ -53,7 +53,7 @@ const thisPane = {
5353 var profile = subject . doc ( )
5454 var editable = UI . store . updater . editable ( profile . uri , kb )
5555
56- main . appendChild ( createText ( 'h3' , 'Manage your trusted applications ' ) )
56+ main . appendChild ( createText ( 'h3' , 'Manage your trusted Web Applications ' ) )
5757
5858 if ( ! editable ) {
5959 main . appendChild ( UI . widgets . errorMessageBlock ( dom , `Your profile ${ subject . doc ( ) . uri } is not editable, so we cannot do much here.` ) )
@@ -67,48 +67,49 @@ const thisPane = {
6767
6868 main . appendChild ( createText ( 'h4' , 'Notes' ) )
6969 main . appendChild ( createContainer ( 'ol' , [
70- main . appendChild ( createText ( 'li' , 'Trusted applications will get access to all resources that you have access to .' ) ) ,
71- main . appendChild ( createText ( 'li' , 'You can limit which modes they have by default .' ) ) ,
72- main . appendChild ( createText ( 'li' , 'They will not gain more access than you have.' ) )
70+ main . appendChild ( createText ( 'li' , 'If put a web app in this list, you can then add it to specific files or folders in the sharing pane .' ) ) ,
71+ main . appendChild ( createText ( 'li' , 'You can also give an app acecss to ALL of you data, by checking the box here. Only do that if you know the app very well .' ) ) ,
72+ main . appendChild ( createText ( 'li' , 'When a person uses the web app, they AND the app must both have access .' ) )
7373 ] ) )
74- main . appendChild ( createText ( 'p' , 'Application URLs must be valid URL. Examples are http://localhost:3000, https://trusted.app, and https://sub.trusted.app.' ) )
74+ main . appendChild ( createText ( 'p' , `Application URLs must be valid URL, without the trailing slash. Examples are https://mine.gihub.io,
75+ http://localhost:3000, https://trusted.app, and https://sub.trusted.app.` ) )
7576 } , err => {
7677 statusArea . appendChild ( UI . widgets . errorMessageBlock ( dom , err ) )
7778 } )
7879 return div
7980 } // render()
8081} //
8182
82- function createApplicationTable ( subject ) {
83+ function createApplicationTable ( subject ) {
8384 var applicationsTable = createElement ( 'table' , {
8485 'class' : 'results'
8586 } )
8687
8788 // creating headers
8889 var header = createContainer ( 'tr' , [
8990 createText ( 'th' , 'Application URL' ) ,
90- createText ( 'th' , 'Access modes' ) ,
91+ createText ( 'th' , 'Access modes to ALL your data ' ) ,
9192 createText ( 'th' , 'Actions' )
9293 ] )
9394 applicationsTable . appendChild ( header )
9495
9596 // creating rows
9697 kb . each ( subject , ns . acl ( 'trustedApp' ) )
97- . flatMap ( app => kb . each ( app , ns . acl ( 'origin' ) ) . map ( origin => ( { appModes : kb . each ( app , ns . acl ( 'mode' ) ) , origin} ) ) )
98- . sort ( ( { origin : a } , { origin : b } ) => a . value < b . value ? - 1 : 1 )
99- . forEach ( ( { appModes, origin} ) => applicationsTable . appendChild ( createApplicationEntry ( subject , origin , appModes , updateTable ) ) )
98+ . flatMap ( app => kb . each ( app , ns . acl ( 'origin' ) ) . map ( origin => ( { appModes : kb . each ( app , ns . acl ( 'mode' ) ) , origin } ) ) )
99+ . sort ( ( { origin : a } , { origin : b } ) => a . value < b . value ? - 1 : 1 )
100+ . forEach ( ( { appModes, origin } ) => applicationsTable . appendChild ( createApplicationEntry ( subject , origin , appModes , updateTable ) ) )
100101
101102 // adding a row for new applications
102103 applicationsTable . appendChild ( createApplicationEntry ( subject , null , [ ns . acl ( 'Read' ) ] , updateTable ) )
103104
104105 return applicationsTable
105106
106- function updateTable ( ) {
107+ function updateTable ( ) {
107108 applicationsTable . parentElement . replaceChild ( createApplicationTable ( subject ) , applicationsTable )
108109 }
109110}
110111
111- function createApplicationEntry ( subject , origin , appModes , updateTable ) {
112+ function createApplicationEntry ( subject , origin , appModes , updateTable ) {
112113 var trustedApplicationState = { origin, appModes, formElements : { modes : [ ] } }
113114 var profile = subject . doc ( )
114115
@@ -127,7 +128,7 @@ function createApplicationEntry(subject, origin, appModes, updateTable) {
127128 'class' : 'controlButton' ,
128129 style : 'background: LightGreen;'
129130 } , {
130- click : ( ) => addOrEditApplication ( )
131+ click : ( ) => addOrEditApplication ( subject )
131132 } ) ,
132133 createText ( 'button' , 'Delete' , {
133134 'class' : 'controlButton' ,
@@ -141,25 +142,26 @@ function createApplicationEntry(subject, origin, appModes, updateTable) {
141142 'class' : 'controlButton' ,
142143 style : 'background: LightGreen;'
143144 } , {
144- click : ( ) => addOrEditApplication ( )
145+ click : ( ) => addOrEditApplication ( subject )
145146 } )
146147 ] )
147148 ] )
148149
149- function addOrEditApplication ( ) {
150- var origin
150+ function addOrEditApplication ( me ) {
151+ const profile = me . doc ( )
152+ let origin
151153 try {
152- origin = $rdf . sym ( trustedApplicationState . formElements . origin . value )
154+ origin = $rdf . sym ( trustedApplicationState . formElements . origin . value . trim ( ) )
153155 } catch ( err ) {
154156 return alert ( 'Please provide an application URL you want to trust' )
155157 }
156158
157159 var deletions = getStatementsToDelete ( origin )
158- var additions = getStatementsToAdd ( origin )
160+ var additions = getStatementsToAdd ( origin , profile )
159161 kb . updater . update ( deletions , additions , handleUpdateResponse )
160162 }
161163
162- function removeApplication ( ) {
164+ function removeApplication ( ) {
163165 var origin
164166 try {
165167 origin = $rdf . sym ( trustedApplicationState . formElements . origin . value )
@@ -171,7 +173,7 @@ function createApplicationEntry(subject, origin, appModes, updateTable) {
171173 kb . updater . update ( deletions , null , handleUpdateResponse )
172174 }
173175
174- function getStatementsToAdd ( origin ) {
176+ function getStatementsToAdd ( origin , profile ) {
175177 var application = new $rdf . BlankNode ( `bn_${ generateRandomString ( ) } ` )
176178 return [
177179 $rdf . st ( subject , ns . acl ( 'trustedApp' ) , application , profile ) ,
@@ -183,23 +185,23 @@ function createApplicationEntry(subject, origin, appModes, updateTable) {
183185 ]
184186 }
185187
186- function getStatementsToDelete ( origin ) {
188+ function getStatementsToDelete ( origin ) {
187189 var applicationStatements = kb . statementsMatching ( null , ns . acl ( 'origin' ) , origin )
188190 return applicationStatements . reduce ( ( memo , st ) => memo
189191 . concat ( kb . statementsMatching ( subject , ns . acl ( 'trustedApp' ) , st . subject ) )
190192 . concat ( kb . statementsMatching ( st . subject ) ) ,
191193 [ ] )
192194 }
193195
194- function handleUpdateResponse ( uri , success , errorBody ) {
196+ function handleUpdateResponse ( uri , success , errorBody ) {
195197 if ( success ) {
196198 return updateTable ( )
197199 }
198200 console . error ( uri , errorBody )
199201 }
200202}
201203
202- function createElement ( elementName , attributes = { } , eventListeners = { } , onCreated = null ) {
204+ function createElement ( elementName , attributes = { } , eventListeners = { } , onCreated = null ) {
203205 var element = document . createElement ( elementName )
204206 if ( onCreated ) {
205207 onCreated ( element )
@@ -213,19 +215,19 @@ function createElement(elementName, attributes = {}, eventListeners = {}, onCrea
213215 return element
214216}
215217
216- function createContainer ( elementName , children , attributes = { } , eventListeners = { } , onCreated = null ) {
218+ function createContainer ( elementName , children , attributes = { } , eventListeners = { } , onCreated = null ) {
217219 var element = createElement ( elementName , attributes , eventListeners , onCreated )
218220 children . forEach ( child => element . appendChild ( child ) )
219221 return element
220222}
221223
222- function createText ( elementName , textContent , attributes = { } , eventListeners = { } , onCreated = null ) {
224+ function createText ( elementName , textContent , attributes = { } , eventListeners = { } , onCreated = null ) {
223225 var element = createElement ( elementName , attributes , eventListeners , onCreated )
224226 element . textContent = textContent
225227 return element
226228}
227229
228- function createModesInput ( { appModes, formElements } ) {
230+ function createModesInput ( { appModes, formElements } ) {
229231 return [ 'Read' , 'Write' , 'Append' , 'Control' ] . map ( mode => {
230232 var isChecked = appModes . some ( appMode => appMode . value === ns . acl ( mode ) . value )
231233 return createContainer ( 'label' , [
@@ -239,7 +241,7 @@ function createModesInput({ appModes, formElements }) {
239241 } )
240242}
241243
242- function generateRandomString ( ) {
244+ function generateRandomString ( ) {
243245 return Math . random ( ) . toString ( 36 ) . substring ( 7 )
244246}
245247
0 commit comments