Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hamza
jio
Commits
c9fc030f
Commit
c9fc030f
authored
Sep 03, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5storage] add access token support
parent
c865b62d
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
741 additions
and
47 deletions
+741
-47
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+38
-30
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+703
-17
No files found.
src/jio.storage/erp5storage.js
View file @
c9fc030f
...
@@ -31,15 +31,32 @@
...
@@ -31,15 +31,32 @@
SimpleQuery
,
ComplexQuery
)
{
SimpleQuery
,
ComplexQuery
)
{
"
use strict
"
;
"
use strict
"
;
function
ajax
(
storage
,
options
)
{
if
(
options
===
undefined
)
{
options
=
{};
}
if
(
options
.
xhrFields
===
undefined
)
{
options
.
xhrFields
=
{};
}
if
(
storage
.
_access_token
!==
undefined
)
{
if
(
options
.
headers
===
undefined
)
{
options
.
headers
=
{};
}
options
.
headers
[
'
X-ACCESS-TOKEN
'
]
=
storage
.
_access_token
;
options
.
xhrFields
.
withCredentials
=
false
;
}
else
{
options
.
xhrFields
.
withCredentials
=
true
;
}
return
jIO
.
util
.
ajax
(
options
);
}
function
getSiteDocument
(
storage
)
{
function
getSiteDocument
(
storage
)
{
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
jIO
.
util
.
ajax
(
{
return
ajax
(
storage
,
{
"
type
"
:
"
GET
"
,
"
type
"
:
"
GET
"
,
"
url
"
:
storage
.
_url
,
"
url
"
:
storage
.
_url
"
xhrFields
"
:
{
withCredentials
:
true
}
});
});
})
})
.
push
(
function
(
event
)
{
.
push
(
function
(
event
)
{
...
@@ -56,16 +73,13 @@
...
@@ -56,16 +73,13 @@
// XXX need to get modified metadata
// XXX need to get modified metadata
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
jIO
.
util
.
ajax
(
{
return
ajax
(
storage
,
{
"
type
"
:
"
GET
"
,
"
type
"
:
"
GET
"
,
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
traverse
.
href
)
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
traverse
.
href
)
.
expand
({
.
expand
({
relative_url
:
id
,
relative_url
:
id
,
view
:
options
.
_view
view
:
options
.
_view
}),
})
"
xhrFields
"
:
{
withCredentials
:
true
}
});
});
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
...
@@ -160,6 +174,9 @@
...
@@ -160,6 +174,9 @@
}
}
this
.
_url
=
spec
.
url
;
this
.
_url
=
spec
.
url
;
this
.
_default_view_reference
=
spec
.
default_view_reference
;
this
.
_default_view_reference
=
spec
.
default_view_reference
;
if
(
spec
.
hasOwnProperty
(
'
access_token
'
))
{
this
.
_access_token
=
spec
.
access_token
;
}
}
}
function
convertJSONToGet
(
json
)
{
function
convertJSONToGet
(
json
)
{
...
@@ -192,13 +209,10 @@
...
@@ -192,13 +209,10 @@
var
form_data
=
new
FormData
();
var
form_data
=
new
FormData
();
form_data
.
append
(
"
portal_type
"
,
data
.
portal_type
);
form_data
.
append
(
"
portal_type
"
,
data
.
portal_type
);
form_data
.
append
(
"
parent_relative_url
"
,
data
.
parent_relative_url
);
form_data
.
append
(
"
parent_relative_url
"
,
data
.
parent_relative_url
);
return
jIO
.
util
.
ajax
(
{
return
ajax
(
context
,
{
type
:
"
POST
"
,
type
:
"
POST
"
,
url
:
site_hal
.
_actions
.
add
.
href
,
url
:
site_hal
.
_actions
.
add
.
href
,
data
:
form_data
,
data
:
form_data
xhrFields
:
{
withCredentials
:
true
}
});
});
})
})
.
push
(
function
(
evt
)
{
.
push
(
function
(
evt
)
{
...
@@ -273,6 +287,7 @@
...
@@ -273,6 +287,7 @@
};
};
ERP5Storage
.
prototype
.
getAttachment
=
function
(
id
,
action
,
options
)
{
ERP5Storage
.
prototype
.
getAttachment
=
function
(
id
,
action
,
options
)
{
var
storage
=
this
;
if
(
options
===
undefined
)
{
if
(
options
===
undefined
)
{
options
=
{};
options
=
{};
}
}
...
@@ -317,10 +332,7 @@
...
@@ -317,10 +332,7 @@
request_options
=
{
request_options
=
{
"
type
"
:
"
GET
"
,
"
type
"
:
"
GET
"
,
"
dataType
"
:
"
blob
"
,
"
dataType
"
:
"
blob
"
,
"
url
"
:
action
,
"
url
"
:
action
"
xhrFields
"
:
{
withCredentials
:
true
}
};
};
if
(
options
.
start
!==
undefined
||
options
.
end
!==
undefined
)
{
if
(
options
.
start
!==
undefined
||
options
.
end
!==
undefined
)
{
start
=
options
.
start
||
0
;
start
=
options
.
start
||
0
;
...
@@ -342,7 +354,7 @@
...
@@ -342,7 +354,7 @@
}
}
request_options
.
headers
=
{
Range
:
range
};
request_options
.
headers
=
{
Range
:
range
};
}
}
return
jIO
.
util
.
ajax
(
request_options
);
return
ajax
(
storage
,
request_options
);
})
})
.
push
(
function
(
evt
)
{
.
push
(
function
(
evt
)
{
if
(
evt
.
target
.
response
===
undefined
)
{
if
(
evt
.
target
.
response
===
undefined
)
{
...
@@ -359,6 +371,7 @@
...
@@ -359,6 +371,7 @@
};
};
ERP5Storage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
ERP5Storage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
var
storage
=
this
;
// Assert we use a callable on a document from the ERP5 site
// Assert we use a callable on a document from the ERP5 site
if
(
name
.
indexOf
(
this
.
_url
)
!==
0
)
{
if
(
name
.
indexOf
(
this
.
_url
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Can not store outside ERP5:
"
+
throw
new
jIO
.
util
.
jIOError
(
"
Can not store outside ERP5:
"
+
...
@@ -394,14 +407,11 @@
...
@@ -394,14 +407,11 @@
}
}
}
}
}
}
return
jIO
.
util
.
ajax
(
{
return
ajax
(
storage
,
{
"
type
"
:
"
POST
"
,
"
type
"
:
"
POST
"
,
"
url
"
:
name
,
"
url
"
:
name
,
"
data
"
:
data
,
"
data
"
:
data
,
"
dataType
"
:
"
blob
"
,
"
dataType
"
:
"
blob
"
"
xhrFields
"
:
{
withCredentials
:
true
}
});
});
});
});
};
};
...
@@ -460,6 +470,7 @@
...
@@ -460,6 +470,7 @@
}
}
ERP5Storage
.
prototype
.
buildQuery
=
function
(
options
)
{
ERP5Storage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
storage
=
this
;
// if (typeof options.query !== "string") {
// if (typeof options.query !== "string") {
// options.query = (options.query ?
// options.query = (options.query ?
// jIO.Query.objectToSearchText(options.query) :
// jIO.Query.objectToSearchText(options.query) :
...
@@ -552,7 +563,7 @@
...
@@ -552,7 +563,7 @@
selection_domain
=
JSON
.
stringify
(
selection_domain
);
selection_domain
=
JSON
.
stringify
(
selection_domain
);
}
}
return
jIO
.
util
.
ajax
(
{
return
ajax
(
storage
,
{
"
type
"
:
"
GET
"
,
"
type
"
:
"
GET
"
,
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
raw_search
.
href
)
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
raw_search
.
href
)
.
expand
({
.
expand
({
...
@@ -563,10 +574,7 @@
...
@@ -563,10 +574,7 @@
sort_on
:
sort_list
,
sort_on
:
sort_list
,
local_roles
:
local_roles
,
local_roles
:
local_roles
,
selection_domain
:
selection_domain
selection_domain
:
selection_domain
}),
})
"
xhrFields
"
:
{
withCredentials
:
true
}
});
});
})
})
.
push
(
function
(
response
)
{
.
push
(
function
(
response
)
{
...
...
test/jio.storage/erp5storage.tests.js
View file @
c9fc030f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment