commit
eba73101b9
@ -1,6 +1,6 @@
|
||||
/*jshint esversion: 6 */
|
||||
const testAuth = (z , bundle) => {
|
||||
const url = bundle.authData.url+'/api/index.php/login';
|
||||
const test = (z , bundle) => {
|
||||
const url = bundle.authData.url+'/api/index.php/status';
|
||||
// Normally you want to make a request to an endpoint that is either specifically designed to test auth, or one that
|
||||
// every user will have access to, such as an account or profile endpoint like /me.
|
||||
// In this example, we'll hit httpbin, which validates the Authorization Header against the arguments passed in the URL path
|
||||
@ -11,67 +11,92 @@ const testAuth = (z , bundle) => {
|
||||
// This method can return any truthy value to indicate the credentials are valid.
|
||||
// Raise an error to show
|
||||
return promise.then((response) => {
|
||||
if (response.status === 401) {
|
||||
throw new Error('The Session Key you supplied is invalid');
|
||||
if (response.status === 400) {
|
||||
throw new Error('400 -The Session Key you supplied is invalid');
|
||||
}
|
||||
if (response.status === 403) {
|
||||
throw new Error('403 -The Session Key you supplied is invalid');
|
||||
}
|
||||
return response;
|
||||
});
|
||||
};
|
||||
|
||||
const getSessionKey = (z, bundle) => {
|
||||
// To include the session key header on all outbound requests, simply define a function here.
|
||||
// It runs runs before each request is sent out, allowing you to make tweaks to the request in a centralized spot
|
||||
const includeSessionKeyHeader = (request, z, bundle) => {
|
||||
if (bundle.authData.sessionKey) {
|
||||
request.headers = request.headers || {};
|
||||
request.headers['DOLAPIKEY'] = bundle.authData.sessionKey;
|
||||
}
|
||||
return request;
|
||||
};
|
||||
|
||||
// If we get a response and it is a 401, we can raise a special error telling Zapier to retry this after another exchange.
|
||||
const sessionRefreshIf401 = (response, z, bundle) => {
|
||||
if (bundle.authData.sessionKey) {
|
||||
if (response.status === 401) {
|
||||
throw new z.errors.RefreshAuthError('Session apikey needs refreshing.');
|
||||
}
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
const getSessionKey = async (z, bundle) => {
|
||||
const url = bundle.authData.url + '/api/index.php/login';
|
||||
|
||||
const promise = z.request({
|
||||
method: 'POST',
|
||||
const response = await z.request({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: {
|
||||
login: bundle.authData.login,
|
||||
password: bundle.authData.password,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return promise.then((response) => {
|
||||
if (response.status === 401) {
|
||||
throw new Error('The login/password you supplied is invalid');
|
||||
}
|
||||
const json = JSON.parse(response.content);
|
||||
return {
|
||||
sessionKey: json.success.token || 'secret'
|
||||
};
|
||||
});
|
||||
// if (response.status === 401) {
|
||||
// throw new Error('The login/password you supplied is invalid');
|
||||
// }
|
||||
const json = JSON.parse(response.content);
|
||||
return {
|
||||
sessionKey: json.success.token || '',
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
type: 'session',
|
||||
// Define any auth fields your app requires here. The user will be prompted to enter this info when
|
||||
// they connect their account.
|
||||
fields: [
|
||||
{
|
||||
key: 'url',
|
||||
label: 'Url of service',
|
||||
required: true,
|
||||
type: 'string'
|
||||
config: {
|
||||
type: 'session',
|
||||
sessionConfig: {
|
||||
perform: getSessionKey
|
||||
},
|
||||
{
|
||||
key: 'login',
|
||||
label: 'Login',
|
||||
required: true,
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: 'password',
|
||||
label: 'Password',
|
||||
required: true,
|
||||
type: 'password'
|
||||
}
|
||||
],
|
||||
// The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this
|
||||
// method whenever a user connects their account for the first time.
|
||||
test: testAuth,
|
||||
// The method that will exchange the fields provided by the user for session credentials.
|
||||
sessionConfig: {
|
||||
perform: getSessionKey
|
||||
// Define any auth fields your app requires here. The user will be prompted to enter this info when
|
||||
// they connect their account.
|
||||
fields: [
|
||||
{
|
||||
key: 'url',
|
||||
label: 'Url of service without trailing-slash',
|
||||
required: true,
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: 'login',
|
||||
label: 'Login',
|
||||
required: true,
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
key: 'password',
|
||||
label: 'Password',
|
||||
required: true,
|
||||
type: 'password'
|
||||
}
|
||||
],
|
||||
// The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this
|
||||
// method whenever a user connects their account for the first time.
|
||||
test,
|
||||
// The method that will exchange the fields provided by the user for session credentials.
|
||||
// assuming "login" is a key returned from the test
|
||||
connectionLabel: '{{login}}'
|
||||
},
|
||||
// assuming "login" is a key returned from the test
|
||||
connectionLabel: '{{login}}'
|
||||
befores: [includeSessionKeyHeader],
|
||||
afters: [sessionRefreshIf401],
|
||||
};
|
||||
|
||||
@ -72,7 +72,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
outputFields: [
|
||||
{key: 'id', label: 'ID'},
|
||||
{key: 'id', type: "integer", label: 'ID'},
|
||||
{key: 'name', label: 'Name'},
|
||||
{key: 'name_alias', label: 'Name alias'},
|
||||
{key: 'address', label: 'Address'},
|
||||
@ -81,8 +81,8 @@ module.exports = {
|
||||
{key: 'phone', label: 'Phone'},
|
||||
{key: 'fax', label: 'Fax'},
|
||||
{key: 'email', label: 'Email'},
|
||||
{key: 'client', label: 'Customer/Prospect 0/1/2/3'},
|
||||
{key: 'fournisseur', label: 'Supplier 0/1'},
|
||||
{key: 'client', type: "integer", label: 'Customer/Prospect 0/1/2/3'},
|
||||
{key: 'fournisseur', type: "integer", label: 'Supplier 0/1'},
|
||||
{key: 'code_client', label: 'Customer code'},
|
||||
{key: 'code_fournisseur', label: 'Supplier code'}
|
||||
]
|
||||
|
||||
@ -1,33 +1,39 @@
|
||||
/*jshint esversion: 6 */
|
||||
const triggerThirdparty = require('./triggers/thirdparty');
|
||||
const triggerOrder = require('./triggers/order');
|
||||
const triggerAction = require('./triggers/action');
|
||||
const triggerOrder = require('./triggers/order');
|
||||
const triggerThirdparty = require('./triggers/thirdparty');
|
||||
const triggerTicket = require('./triggers/ticket');
|
||||
const triggerUser = require('./triggers/user');
|
||||
|
||||
const searchThirdparty = require('./searches/thirdparty');
|
||||
|
||||
const createThirdparty = require('./creates/thirdparty');
|
||||
|
||||
const authentication = require('./authentication');
|
||||
const {
|
||||
config: authentication,
|
||||
befores = [],
|
||||
afters = [],
|
||||
} = require('./authentication');
|
||||
|
||||
// To include the session key header on all outbound requests, simply define a function here.
|
||||
// It runs runs before each request is sent out, allowing you to make tweaks to the request in a centralized spot
|
||||
const includeSessionKeyHeader = (request, z, bundle) => {
|
||||
if (bundle.authData.sessionKey) {
|
||||
request.headers = request.headers || {};
|
||||
request.headers['DOLAPIKEY'] = bundle.authData.sessionKey;
|
||||
}
|
||||
return request;
|
||||
};
|
||||
// const includeSessionKeyHeader = (request, z, bundle) => {
|
||||
// if (bundle.authData.sessionKey) {
|
||||
// request.headers = request.headers || {};
|
||||
// request.headers['DOLAPIKEY'] = bundle.authData.sessionKey;
|
||||
// }
|
||||
// return request;
|
||||
// };
|
||||
|
||||
// If we get a response and it is a 401, we can raise a special error telling Zapier to retry this after another exchange.
|
||||
const sessionRefreshIf401 = (response, z, bundle) => {
|
||||
if (bundle.authData.sessionKey) {
|
||||
if (response.status === 401) {
|
||||
throw new z.errors.RefreshAuthError('Session apikey needs refreshing.');
|
||||
}
|
||||
}
|
||||
return response;
|
||||
};
|
||||
// const sessionRefreshIf401 = (response, z, bundle) => {
|
||||
// if (bundle.authData.sessionKey) {
|
||||
// if (response.status === 401) {
|
||||
// throw new z.errors.RefreshAuthError('Session apikey needs refreshing.');
|
||||
// }
|
||||
// }
|
||||
// return response;
|
||||
// };
|
||||
|
||||
// We can roll up all our behaviors in an App.
|
||||
const App = {
|
||||
@ -40,11 +46,11 @@ const App = {
|
||||
|
||||
// beforeRequest & afterResponse are optional hooks into the provided HTTP client
|
||||
beforeRequest: [
|
||||
includeSessionKeyHeader
|
||||
...befores
|
||||
],
|
||||
|
||||
afterResponse: [
|
||||
sessionRefreshIf401
|
||||
...afters
|
||||
],
|
||||
|
||||
// If you want to define optional resources to simplify creation of triggers, searches, creates - do that here!
|
||||
@ -53,9 +59,11 @@ const App = {
|
||||
|
||||
// If you want your trigger to show up, you better include it here!
|
||||
triggers: {
|
||||
[triggerThirdparty.key]: triggerThirdparty,
|
||||
[triggerAction.key]: triggerAction,
|
||||
[triggerOrder.key]: triggerOrder,
|
||||
[triggerAction.key]: triggerAction
|
||||
[triggerThirdparty.key]: triggerThirdparty,
|
||||
[triggerTicket.key]: triggerTicket,
|
||||
[triggerUser.key]: triggerUser,
|
||||
},
|
||||
|
||||
// If you want your searches to show up, you better include it here!
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dolibarr",
|
||||
"version": "1.0.0",
|
||||
"version": "1.13.0",
|
||||
"description": "An app for connecting Dolibarr to the Zapier platform.",
|
||||
"repository": "Dolibarr/dolibarr",
|
||||
"homepage": "https://www.dolibarr.org/",
|
||||
@ -15,7 +15,7 @@
|
||||
"npm": ">=5.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"zapier-platform-core": "8.0.1"
|
||||
"zapier-platform-core": "10.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^5.2.0",
|
||||
|
||||
@ -54,13 +54,20 @@ module.exports = {
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{key: 'id', label: 'ID'},
|
||||
{key: 'createdAt', label: 'Created At'},
|
||||
{
|
||||
key: 'id',
|
||||
type: "integer",
|
||||
label: 'ID'
|
||||
},
|
||||
{key: 'createdAt', type: "integer", label: 'Created At'},
|
||||
{key: 'name', label: 'Name'},
|
||||
{key: 'firstname', label: 'Firstname'},
|
||||
{key: 'directions', label: 'Directions'},
|
||||
{key: 'authorId', label: 'Author ID'},
|
||||
{key: 'style', label: 'Style'}
|
||||
{key: 'authorId', type: "integer", label: 'Author ID'},
|
||||
{
|
||||
key: 'style',
|
||||
label: 'Style'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@ -10,14 +10,14 @@ const subscribeHook = (z, bundle) => {
|
||||
action: bundle.inputData.action
|
||||
};
|
||||
|
||||
const url = bundle.authData.url + '/api/index.php/zapierapi/hook';
|
||||
const url = bundle.authData.url + '/api/index.php/zapierapi/hook';
|
||||
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
body: data,
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
@ -32,7 +32,7 @@ const unsubscribeHook = (z, bundle) => {
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/zapierapi/hook/' + bundle.subscribeData.id,
|
||||
url: bundle.authData.url + '/api/index.php/zapierapi/hook/' + bundle.subscribeData.id,
|
||||
method: 'DELETE',
|
||||
};
|
||||
|
||||
@ -74,7 +74,7 @@ const getFallbackRealAction = (z, bundle) => {
|
||||
// For the test poll, you should get some real data, to aid the setup process.
|
||||
const module = bundle.inputData.module;
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/agendaevents/0',
|
||||
url: bundle.authData.url + '/api/index.php/agendaevents/0',
|
||||
};
|
||||
|
||||
return z.request(options).then((response) => [JSON.parse(response.content)]);
|
||||
@ -100,7 +100,7 @@ module.exports = {
|
||||
noun: 'Action',
|
||||
display: {
|
||||
label: 'New Agenda',
|
||||
description: 'Trigger when a new agenda with action is done in Dolibarr.'
|
||||
description: 'Triggers when a new agenda with action is done in Dolibarr.'
|
||||
},
|
||||
|
||||
// `operation` is where the business logic goes.
|
||||
@ -111,6 +111,7 @@ module.exports = {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'action',
|
||||
required: true,
|
||||
type: 'string',
|
||||
helpText: 'Which action of agenda this should trigger on.',
|
||||
choices: {
|
||||
@ -145,12 +146,33 @@ module.exports = {
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{key: 'id', label: 'ID'},
|
||||
{key: 'createdAt', label: 'Created At'},
|
||||
{key: 'name', label: 'Name'},
|
||||
{key: 'usertodo__name', label: 'UserToDo Name'},
|
||||
{key: 'authorId', label: 'Author ID'},
|
||||
{key: 'action', label: 'Action'}
|
||||
{
|
||||
key: 'id',
|
||||
type: "integer",
|
||||
label: 'ID'
|
||||
},
|
||||
{
|
||||
key: 'createdAt',
|
||||
type: "integer",
|
||||
label: 'Created At'
|
||||
},
|
||||
{
|
||||
key: 'name',
|
||||
label: 'Name'
|
||||
},
|
||||
{
|
||||
key: 'usertodo__name',
|
||||
label: 'UserToDo Name'
|
||||
},
|
||||
{
|
||||
key: 'authorId',
|
||||
type: "integer",
|
||||
label: 'Author ID'
|
||||
},
|
||||
{
|
||||
key: 'action',
|
||||
label: 'Action'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@ -17,7 +17,7 @@ const subscribeHook = (z, bundle) => {
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
body: data,
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
@ -90,7 +90,7 @@ module.exports = {
|
||||
noun: 'Order',
|
||||
display: {
|
||||
label: 'New Order',
|
||||
description: 'Trigger when a new order with action is done in Dolibarr.'
|
||||
description: 'Triggers when a new order with action is done in Dolibarr.'
|
||||
},
|
||||
|
||||
// `operation` is where the business logic goes.
|
||||
@ -101,6 +101,7 @@ module.exports = {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'action',
|
||||
required: true,
|
||||
type: 'string',
|
||||
helpText: 'Which action of order this should trigger on.',
|
||||
choices: {
|
||||
@ -136,11 +137,11 @@ module.exports = {
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{key: 'id', label: 'ID'},
|
||||
{key: 'createdAt', label: 'Created At'},
|
||||
{key: 'id', type: "integer", label: 'ID'},
|
||||
{key: 'createdAt', type: "integer", label: 'Created At'},
|
||||
{key: 'name', label: 'Name'},
|
||||
{key: 'directions', label: 'Directions'},
|
||||
{key: 'authorId', label: 'Author ID'},
|
||||
{key: 'authorId', type: "integer", label: 'Author ID'},
|
||||
{key: 'module', label: 'Module'},
|
||||
{key: 'action', label: 'Action'}
|
||||
]
|
||||
|
||||
@ -17,7 +17,7 @@ const subscribeHook = (z, bundle) => {
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
body: data,
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
@ -112,7 +112,7 @@ module.exports = {
|
||||
noun: 'Thirdparty',
|
||||
display: {
|
||||
label: 'New Thirdparty',
|
||||
description: 'Trigger when a new thirdpaty action is done in Dolibarr.'
|
||||
description: 'Triggers when a new thirdpaty action is done in Dolibarr.'
|
||||
},
|
||||
|
||||
// `operation` is where the business logic goes.
|
||||
@ -123,6 +123,7 @@ module.exports = {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'action',
|
||||
required: true,
|
||||
type: 'string',
|
||||
helpText: 'Which action of thirdparty this should trigger on.',
|
||||
choices: {
|
||||
@ -159,12 +160,12 @@ module.exports = {
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{key: 'id', label: 'ID'},
|
||||
{key: 'id', type: "integer", label: 'ID'},
|
||||
{key: 'createdAt', label: 'Created At'},
|
||||
{key: 'name', label: 'Name'},
|
||||
{key: 'name_alias', label: 'Name alias'},
|
||||
{key: 'firstname', label: 'Firstame'},
|
||||
{key: 'authorId', label: 'Author ID'},
|
||||
{key: 'firstname', label: 'Firstname'},
|
||||
{key: 'authorId', type: "integer", label: 'Author ID'},
|
||||
{key: 'action', label: 'Action'},
|
||||
{key: 'client', label: 'Customer/Prospect 0/1/2/3'},
|
||||
{key: 'fournisseur', label: 'Supplier 0/1'},
|
||||
|
||||
237
dev/examples/zapier/triggers/ticket.js
Normal file
237
dev/examples/zapier/triggers/ticket.js
Normal file
@ -0,0 +1,237 @@
|
||||
const subscribeHook = (z, bundle) => {
|
||||
// `z.console.log()` is similar to `console.log()`.
|
||||
z.console.log('suscribing hook!');
|
||||
|
||||
// bundle.targetUrl has the Hook URL this app should call when an action is created.
|
||||
const data = {
|
||||
url: bundle.targetUrl,
|
||||
event: bundle.event,
|
||||
module: 'ticket',
|
||||
action: bundle.inputData.action
|
||||
};
|
||||
|
||||
const url = bundle.authData.url + '/api/index.php/zapierapi/hook';
|
||||
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: data,
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
return z.request(options).then((response) => JSON.parse(response.content));
|
||||
};
|
||||
|
||||
const unsubscribeHook = (z, bundle) => {
|
||||
// bundle.subscribeData contains the parsed response JSON from the subscribe
|
||||
// request made initially.
|
||||
z.console.log('unsuscribing hook!');
|
||||
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/zapierapi/hook/' + bundle.subscribeData.id,
|
||||
method: 'DELETE',
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
return z.request(options).then((response) => JSON.parse(response.content));
|
||||
};
|
||||
|
||||
const getTicket = (z, bundle) => {
|
||||
// bundle.cleanedRequest will include the parsed JSON object (if it's not a
|
||||
// test poll) and also a .querystring property with the URL's query string.
|
||||
const ticket = {
|
||||
id: bundle.cleanedRequest.id,
|
||||
track_id: bundle.cleanedRequest.track_id,
|
||||
subject: bundle.cleanedRequest.subject,
|
||||
message: bundle.cleanedRequest.message,
|
||||
lastname: bundle.cleanedRequest.lastname,
|
||||
firstname: bundle.cleanedRequest.firstname,
|
||||
address: bundle.cleanedRequest.address,
|
||||
zip: bundle.cleanedRequest.zip,
|
||||
town: bundle.cleanedRequest.town,
|
||||
email_from: bundle.cleanedRequest.email_from,
|
||||
login: bundle.cleanedRequest.login,
|
||||
authorId: bundle.cleanedRequest.authorId,
|
||||
createdAt: bundle.cleanedRequest.createdAt,
|
||||
action: bundle.cleanedRequest.action
|
||||
};
|
||||
|
||||
return [ticket];
|
||||
};
|
||||
|
||||
const getFallbackRealTicket = (z, bundle) => {
|
||||
// For the test poll, you should get some real data, to aid the setup process.
|
||||
const module = bundle.inputData.module;
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/tickets/0',
|
||||
};
|
||||
|
||||
return z.request(options).then((response) => [JSON.parse(response.content)]);
|
||||
};
|
||||
|
||||
// const getModulesChoices = (z/*, bundle*/) => {
|
||||
// // For the test poll, you should get some real data, to aid the setup process.
|
||||
// const options = {
|
||||
// url: bundle.authData.url + '/api/index.php/zapierapi/getmoduleschoices',
|
||||
// };
|
||||
|
||||
// return z.request(options).then((response) => JSON.parse(response.content));
|
||||
// };
|
||||
// const getModulesChoices = () => {
|
||||
|
||||
// return {
|
||||
// orders: "Order",
|
||||
// invoices: "Invoice",
|
||||
// thirdparties: "Thirdparty",
|
||||
// users: "User",
|
||||
// tickets: "Ticket",
|
||||
// contacts: "Contacts"
|
||||
// };
|
||||
// };
|
||||
|
||||
// const getActionsChoices = (z, bundle) => {
|
||||
// // For the test poll, you should get some real data, to aid the setup process.
|
||||
// const module = bundle.inputData.module;
|
||||
// const options = {
|
||||
// url: url: bundle.authData.url + '/api/index.php/zapierapi/getactionschoices/thirparty`,
|
||||
// };
|
||||
|
||||
// return z.request(options).then((response) => JSON.parse(response.content));
|
||||
// };
|
||||
|
||||
// We recommend writing your triggers separate like this and rolling them
|
||||
// into the App definition at the end.
|
||||
module.exports = {
|
||||
key: 'ticket',
|
||||
|
||||
// You'll want to provide some helpful display labels and descriptions
|
||||
// for tickets. Zapier will put them into the UX.
|
||||
noun: 'Ticket',
|
||||
display: {
|
||||
label: 'New Ticket',
|
||||
description: 'Triggers when a new ticket action is done in Dolibarr.'
|
||||
},
|
||||
|
||||
// `operation` is where the business logic goes.
|
||||
operation: {
|
||||
|
||||
// `inputFields` can define the fields a ticket could provide,
|
||||
// we'll pass them in as `bundle.inputData` later.
|
||||
inputFields: [
|
||||
{
|
||||
key: 'action',
|
||||
type: 'string',
|
||||
required: true,
|
||||
helpText: 'Which action of ticket this should trigger on.',
|
||||
choices: {
|
||||
create: "Create",
|
||||
modify: "Modify",
|
||||
validate: "Validate",
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
type: 'hook',
|
||||
|
||||
performSubscribe: subscribeHook,
|
||||
performUnsubscribe: unsubscribeHook,
|
||||
|
||||
perform: getTicket,
|
||||
performList: getFallbackRealTicket,
|
||||
|
||||
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
|
||||
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
|
||||
// returned records, and have obviously dummy values that we can show to any user.
|
||||
sample: {
|
||||
id: 1,
|
||||
track_id: 'Xaz123er',
|
||||
subject: 'Subject',
|
||||
message: 'Message',
|
||||
createdAt: 1472069465,
|
||||
lastname: 'DOE',
|
||||
firstname: 'John',
|
||||
email: 'john@doe.com',
|
||||
address: 'Park Avenue',
|
||||
zip: '12345',
|
||||
town: 'NEW-YORK',
|
||||
email_from: 'doe.john@example;com',
|
||||
authorId: 1,
|
||||
action: 'create'
|
||||
},
|
||||
|
||||
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
|
||||
// field definitions. The result will be used to augment the sample.
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{
|
||||
key: 'id',
|
||||
type: "integer",
|
||||
label: 'ID'
|
||||
},
|
||||
{
|
||||
key: 'track_id',
|
||||
type: "string",
|
||||
label: 'TrackID'
|
||||
},
|
||||
{
|
||||
key: 'subject',
|
||||
type: "string",
|
||||
label: 'Subject'
|
||||
},
|
||||
{
|
||||
key: 'message',
|
||||
type: "string",
|
||||
label: 'Message'
|
||||
},
|
||||
{
|
||||
key: 'createdAt',
|
||||
type: "integer",
|
||||
label: 'Created At'
|
||||
},
|
||||
{
|
||||
key: 'lastname',
|
||||
label: 'Lastname'
|
||||
},
|
||||
{
|
||||
key: 'firstname',
|
||||
label: 'Firstname'
|
||||
},
|
||||
{
|
||||
key: 'email',
|
||||
label: 'Email'
|
||||
},
|
||||
{
|
||||
key: 'address',
|
||||
label: 'Address'
|
||||
},
|
||||
{
|
||||
key: 'zip',
|
||||
label: 'Zip'
|
||||
},
|
||||
{
|
||||
key: 'town',
|
||||
label: 'Town'
|
||||
},
|
||||
{
|
||||
key: 'email_from',
|
||||
type: 'string',
|
||||
label: 'Email from'
|
||||
},
|
||||
{
|
||||
key: 'authorId',
|
||||
type: "integer",
|
||||
label: 'Author ID'
|
||||
},
|
||||
{
|
||||
key: 'action',
|
||||
type: 'string',
|
||||
label: 'Action'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
177
dev/examples/zapier/triggers/user.js
Normal file
177
dev/examples/zapier/triggers/user.js
Normal file
@ -0,0 +1,177 @@
|
||||
const subscribeHook = (z, bundle) => {
|
||||
// `z.console.log()` is similar to `console.log()`.
|
||||
z.console.log('suscribing hook!');
|
||||
|
||||
// bundle.targetUrl has the Hook URL this app should call when an action is created.
|
||||
const data = {
|
||||
url: bundle.targetUrl,
|
||||
event: bundle.event,
|
||||
module: 'user',
|
||||
action: bundle.inputData.action
|
||||
};
|
||||
|
||||
const url = bundle.authData.url + '/api/index.php/zapierapi/hook';
|
||||
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: data,
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
return z.request(options).then((response) => JSON.parse(response.content));
|
||||
};
|
||||
|
||||
const unsubscribeHook = (z, bundle) => {
|
||||
// bundle.subscribeData contains the parsed response JSON from the subscribe
|
||||
// request made initially.
|
||||
z.console.log('unsuscribing hook!');
|
||||
|
||||
// You can build requests and our client will helpfully inject all the variables
|
||||
// you need to complete. You can also register middleware to control this.
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/zapierapi/hook/' + bundle.subscribeData.id,
|
||||
method: 'DELETE',
|
||||
};
|
||||
|
||||
// You may return a promise or a normal data structure from any perform method.
|
||||
return z.request(options).then((response) => JSON.parse(response.content));
|
||||
};
|
||||
|
||||
const getUser = (z, bundle) => {
|
||||
// bundle.cleanedRequest will include the parsed JSON object (if it's not a
|
||||
// test poll) and also a .querystring property with the URL's query string.
|
||||
const user = {
|
||||
id: bundle.cleanedRequest.id,
|
||||
lastname: bundle.cleanedRequest.lastname,
|
||||
firstname: bundle.cleanedRequest.firstname,
|
||||
address: bundle.cleanedRequest.address,
|
||||
zip: bundle.cleanedRequest.zip,
|
||||
town: bundle.cleanedRequest.town,
|
||||
email: bundle.cleanedRequest.email,
|
||||
login: bundle.cleanedRequest.login,
|
||||
authorId: bundle.cleanedRequest.authorId,
|
||||
createdAt: bundle.cleanedRequest.createdAt,
|
||||
action: bundle.cleanedRequest.action
|
||||
};
|
||||
|
||||
return [user];
|
||||
};
|
||||
|
||||
const getFallbackRealUser = (z, bundle) => {
|
||||
// For the test poll, you should get some real data, to aid the setup process.
|
||||
const module = bundle.inputData.module;
|
||||
const options = {
|
||||
url: bundle.authData.url + '/api/index.php/users/0',
|
||||
};
|
||||
|
||||
return z.request(options).then((response) => [JSON.parse(response.content)]);
|
||||
};
|
||||
|
||||
// const getModulesChoices = (z/*, bundle*/) => {
|
||||
// // For the test poll, you should get some real data, to aid the setup process.
|
||||
// const options = {
|
||||
// url: bundle.authData.url + '/api/index.php/zapierapi/getmoduleschoices',
|
||||
// };
|
||||
|
||||
// return z.request(options).then((response) => JSON.parse(response.content));
|
||||
// };
|
||||
// const getModulesChoices = () => {
|
||||
|
||||
// return {
|
||||
// orders: "Order",
|
||||
// invoices: "Invoice",
|
||||
// thirdparties: "Thirdparty",
|
||||
// users: "User",
|
||||
// contacts: "Contacts"
|
||||
// };
|
||||
// };
|
||||
|
||||
// const getActionsChoices = (z, bundle) => {
|
||||
// // For the test poll, you should get some real data, to aid the setup process.
|
||||
// const module = bundle.inputData.module;
|
||||
// const options = {
|
||||
// url: url: bundle.authData.url + '/api/index.php/zapierapi/getactionschoices/thirparty`,
|
||||
// };
|
||||
|
||||
// return z.request(options).then((response) => JSON.parse(response.content));
|
||||
// };
|
||||
|
||||
// We recommend writing your triggers separate like this and rolling them
|
||||
// into the App definition at the end.
|
||||
module.exports = {
|
||||
key: 'user',
|
||||
|
||||
// You'll want to provide some helpful display labels and descriptions
|
||||
// for users. Zapier will put them into the UX.
|
||||
noun: 'User',
|
||||
display: {
|
||||
label: 'New User',
|
||||
description: 'Triggers when a new user action is done in Dolibarr.'
|
||||
},
|
||||
|
||||
// `operation` is where the business logic goes.
|
||||
operation: {
|
||||
|
||||
// `inputFields` can define the fields a user could provide,
|
||||
// we'll pass them in as `bundle.inputData` later.
|
||||
inputFields: [
|
||||
{
|
||||
key: 'action',
|
||||
required: true,
|
||||
type: 'string',
|
||||
helpText: 'Which action of user this should trigger on.',
|
||||
choices: {
|
||||
create: "Create",
|
||||
modify: "Modify",
|
||||
validate: "Validate",
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
type: 'hook',
|
||||
|
||||
performSubscribe: subscribeHook,
|
||||
performUnsubscribe: unsubscribeHook,
|
||||
|
||||
perform: getUser,
|
||||
performList: getFallbackRealUser,
|
||||
|
||||
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
|
||||
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
|
||||
// returned records, and have obviously dummy values that we can show to any user.
|
||||
sample: {
|
||||
id: 1,
|
||||
createdAt: 1472069465,
|
||||
lastname: 'DOE',
|
||||
firstname: 'John',
|
||||
email: 'john@doe.com',
|
||||
address: 'Park Avenue',
|
||||
zip: '12345',
|
||||
town: 'NEW-YORK',
|
||||
login: 'doe.john',
|
||||
authorId: 1,
|
||||
action: 'create'
|
||||
},
|
||||
|
||||
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
|
||||
// field definitions. The result will be used to augment the sample.
|
||||
// outputFields: () => { return []; }
|
||||
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||
outputFields: [
|
||||
{key: 'id', type: "integer", label: 'ID'},
|
||||
{key: 'createdAt', type: "integer", label: 'Created At'},
|
||||
{key: 'lastname', label: 'Lastname'},
|
||||
{key: 'firstname', label: 'Firstname'},
|
||||
{key: 'email', label: 'Email'},
|
||||
{key: 'address', label: 'Address'},
|
||||
{key: 'zip', label: 'Zip'},
|
||||
{key: 'town', label: 'Town'},
|
||||
{key: 'login', label: 'Login'},
|
||||
{key: 'authorId', type: "integer", label: 'Author ID'},
|
||||
{key: 'action', label: 'Action'}
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -2306,14 +2306,16 @@ class Adherent extends CommonObject
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function initAsSpecimen()
|
||||
{
|
||||
global $user, $langs;
|
||||
$now = dol_now();
|
||||
|
||||
// Initialise parametres
|
||||
$this->id = 0;
|
||||
$this->entity = 1;
|
||||
$this->specimen = 1;
|
||||
$this->civility_id = 0;
|
||||
$this->lastname = 'DOLIBARR';
|
||||
@ -2330,24 +2332,30 @@ class Adherent extends CommonObject
|
||||
$this->country = 'France';
|
||||
$this->morphy = 'mor';
|
||||
$this->email = 'specimen@specimen.com';
|
||||
$this->socialnetworks = array('skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', 'facebook' => 'facebookpseudo', 'linkedin' => 'linkedinpseudo');
|
||||
$this->socialnetworks = array(
|
||||
'skype' => 'skypepseudo',
|
||||
'twitter' => 'twitterpseudo',
|
||||
'facebook' => 'facebookpseudo',
|
||||
'linkedin' => 'linkedinpseudo',
|
||||
);
|
||||
$this->phone = '0999999999';
|
||||
$this->phone_perso = '0999999998';
|
||||
$this->phone_mobile = '0999999997';
|
||||
$this->note_private = 'No comment';
|
||||
$this->birth = time();
|
||||
$this->note_public = 'This is a public note';
|
||||
$this->note_private = 'This is a private note';
|
||||
$this->birth = $now;
|
||||
$this->photo = '';
|
||||
$this->public = 1;
|
||||
$this->statut = 0;
|
||||
|
||||
$this->datefin = time();
|
||||
$this->datevalid = time();
|
||||
$this->datefin = $now;
|
||||
$this->datevalid = $now;
|
||||
|
||||
$this->typeid = 1; // Id type adherent
|
||||
$this->type = 'Type adherent'; // Libelle type adherent
|
||||
$this->need_subscription = 0;
|
||||
|
||||
$this->first_subscription_date = time();
|
||||
$this->first_subscription_date = $now;
|
||||
$this->first_subscription_date_start = $this->first_subscription_date;
|
||||
$this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
|
||||
$this->first_subscription_amount = 10;
|
||||
@ -2356,6 +2364,7 @@ class Adherent extends CommonObject
|
||||
$this->last_subscription_date_start = $this->first_subscription_date;
|
||||
$this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
|
||||
$this->last_subscription_amount = 10;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -67,12 +67,16 @@ class Members extends DolibarrApi
|
||||
}
|
||||
|
||||
$member = new Adherent($this->db);
|
||||
$result = $member->fetch($id);
|
||||
if ($id == 0) {
|
||||
$result = $member->initAsSpecimen();
|
||||
} else {
|
||||
$result = $member->fetch($id);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'member not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) {
|
||||
if (!DolibarrApi::_checkAccessToResource('adherent', $member->id) && $id > 0) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
|
||||
@ -78,15 +78,15 @@ class DolibarrApi
|
||||
* @return array
|
||||
*/
|
||||
/* Disabled, most APIs does not share same signature for method index
|
||||
function index()
|
||||
{
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => __class__.' is up and running!'
|
||||
)
|
||||
);
|
||||
}*/
|
||||
function index()
|
||||
{
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => __class__.' is up and running!'
|
||||
)
|
||||
);
|
||||
}*/
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
||||
/**
|
||||
@ -221,11 +221,9 @@ class DolibarrApi
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($object->thirdparty) && is_object($object->thirdparty))
|
||||
{
|
||||
if (!empty($object->thirdparty) && is_object($object->thirdparty)) {
|
||||
$this->_cleanObjectDatas($object->thirdparty);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
@ -229,9 +229,7 @@ class Documents extends DolibarrApi
|
||||
if ($result <= 0) {
|
||||
throw new RestException(500, 'Error generating document');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new RestException(403, 'Generation not available for this modulepart');
|
||||
}
|
||||
|
||||
@ -277,6 +275,8 @@ class Documents extends DolibarrApi
|
||||
}
|
||||
|
||||
$id = (empty($id) ? 0 : $id);
|
||||
$recursive = 0;
|
||||
$type = 'files';
|
||||
|
||||
if ($modulepart == 'societe' || $modulepart == 'thirdparty')
|
||||
{
|
||||
@ -474,11 +474,27 @@ class Documents extends DolibarrApi
|
||||
}
|
||||
|
||||
$upload_dir = $conf->categorie->multidir_output[$object->entity].'/'.get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/".dol_sanitizeFileName($object->ref);
|
||||
} elseif ($modulepart == 'ecm') {
|
||||
throw new RestException(500, 'Modulepart Ecm not implemented yet.');
|
||||
// // require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
|
||||
|
||||
// if (!DolibarrApiAccess::$user->rights->ecm->read) {
|
||||
// throw new RestException(401);
|
||||
// }
|
||||
|
||||
// // $object = new EcmDirectory($this->db);
|
||||
// // $result = $object->fetch($ref);
|
||||
// // if (!$result) {
|
||||
// // throw new RestException(404, 'EcmDirectory not found');
|
||||
// // }
|
||||
// $upload_dir = $conf->ecm->dir_output;
|
||||
// $type = 'all';
|
||||
// $recursive = 0;
|
||||
} else {
|
||||
throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
|
||||
}
|
||||
|
||||
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
|
||||
$filearray = dol_dir_list($upload_dir, $type, $recursive, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
|
||||
if (empty($filearray)) {
|
||||
throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->ref) ? ' or Ref '.$object->ref : '').' does not return any document.');
|
||||
}
|
||||
@ -592,9 +608,7 @@ class Documents extends DolibarrApi
|
||||
{
|
||||
$tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new RestException(500, 'Error while fetching Task '.$ref);
|
||||
}
|
||||
}
|
||||
@ -619,10 +633,8 @@ class Documents extends DolibarrApi
|
||||
$modulepart = 'propale';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
$object = new Propal($this->db);
|
||||
}
|
||||
// TODO Implement additional moduleparts
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// TODO Implement additional moduleparts
|
||||
throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
|
||||
}
|
||||
|
||||
@ -660,9 +672,7 @@ class Documents extends DolibarrApi
|
||||
{
|
||||
throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($modulepart == 'invoice') $modulepart = 'facture';
|
||||
if ($modulepart == 'member') $modulepart = 'adherent';
|
||||
|
||||
@ -700,20 +710,16 @@ class Documents extends DolibarrApi
|
||||
}
|
||||
|
||||
$fhandle = @fopen($destfiletmp, 'w');
|
||||
if ($fhandle)
|
||||
{
|
||||
if ($fhandle) {
|
||||
$nbofbyteswrote = fwrite($fhandle, $newfilecontent);
|
||||
fclose($fhandle);
|
||||
@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
|
||||
}
|
||||
|
||||
$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
|
||||
if (!$result)
|
||||
{
|
||||
if (!$result) {
|
||||
throw new RestException(500, "Failed to move file into '".$destfile."'");
|
||||
}
|
||||
|
||||
|
||||
@ -85,8 +85,28 @@ class InterfaceZapierTriggers extends DolibarrTriggers
|
||||
|
||||
switch ($action) {
|
||||
// Users
|
||||
//case 'USER_CREATE':
|
||||
//case 'USER_MODIFY':
|
||||
case 'USER_CREATE':
|
||||
$resql = $this->db->query($sql);
|
||||
// TODO voir comment regrouper les webhooks en un post
|
||||
while ($resql && $obj = $this->db->fetch_array($resql)) {
|
||||
$cleaned = cleanObjectDatas(dol_clone($object));
|
||||
$json = json_encode($cleaned);
|
||||
// call the zapierPostWebhook() function
|
||||
zapierPostWebhook($obj['url'], $json);
|
||||
}
|
||||
$logtriggeraction = true;
|
||||
break;
|
||||
case 'USER_MODIFY':
|
||||
$resql = $this->db->query($sql);
|
||||
// TODO voir comment regrouper les webhooks en un post
|
||||
while ($resql && $obj = $this->db->fetch_array($resql)) {
|
||||
$cleaned = cleanObjectDatas(dol_clone($object));
|
||||
$json = json_encode($cleaned);
|
||||
// call the zapierPostWebhook() function
|
||||
zapierPostWebhook($obj['url'], $json);
|
||||
}
|
||||
$logtriggeraction = true;
|
||||
break;
|
||||
//case 'USER_NEW_PASSWORD':
|
||||
//case 'USER_ENABLEDISABLE':
|
||||
//case 'USER_DELETE':
|
||||
@ -124,6 +144,12 @@ class InterfaceZapierTriggers extends DolibarrTriggers
|
||||
//case 'USERGROUP_MODIFY':
|
||||
//case 'USERGROUP_DELETE':
|
||||
|
||||
// Categories
|
||||
// case 'CATEGORY_CREATE':
|
||||
// case 'CATEGORY_MODIFY':
|
||||
// case 'CATEGORY_DELETE':
|
||||
// case 'CATEGORY_SET_MULTILANGS':
|
||||
|
||||
// Companies
|
||||
case 'COMPANY_CREATE':
|
||||
$resql = $this->db->query($sql);
|
||||
@ -305,12 +331,6 @@ class InterfaceZapierTriggers extends DolibarrTriggers
|
||||
// case 'MEMBER_RESILIATE':
|
||||
// case 'MEMBER_DELETE':
|
||||
|
||||
// Categories
|
||||
// case 'CATEGORY_CREATE':
|
||||
// case 'CATEGORY_MODIFY':
|
||||
// case 'CATEGORY_DELETE':
|
||||
// case 'CATEGORY_SET_MULTILANGS':
|
||||
|
||||
// Projects
|
||||
// case 'PROJECT_CREATE':
|
||||
// case 'PROJECT_MODIFY':
|
||||
@ -325,6 +345,21 @@ class InterfaceZapierTriggers extends DolibarrTriggers
|
||||
// case 'TASK_TIMESPENT_CREATE':
|
||||
// case 'TASK_TIMESPENT_MODIFY':
|
||||
// case 'TASK_TIMESPENT_DELETE':
|
||||
case 'TICKET_CREATE':
|
||||
$resql = $this->db->query($sql);
|
||||
// TODO voir comment regrouper les webhooks en un post
|
||||
while ($resql && $obj = $this->db->fetch_array($resql)) {
|
||||
$cleaned = cleanObjectDatas(dol_clone($object));
|
||||
$json = json_encode($cleaned);
|
||||
// call the zapierPostWebhook() function
|
||||
zapierPostWebhook($obj['url'], $json);
|
||||
}
|
||||
$logtriggeraction = true;
|
||||
break;
|
||||
// case 'TICKET_MODIFY':
|
||||
// break;
|
||||
// case 'TICKET_DELETE':
|
||||
// break;
|
||||
|
||||
// Shipping
|
||||
// case 'SHIPPING_CREATE':
|
||||
@ -439,13 +474,13 @@ function cleanObjectDatas($toclean)
|
||||
|
||||
// If object has linked objects, remove $db property
|
||||
/*
|
||||
if(isset($toclean->linkedObjects) && count($toclean->linkedObjects) > 0) {
|
||||
foreach($toclean->linkedObjects as $type_object => $linked_object) {
|
||||
foreach($linked_object as $toclean2clean) {
|
||||
$this->cleanObjectDatas($toclean2clean);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if(isset($toclean->linkedObjects) && count($toclean->linkedObjects) > 0) {
|
||||
foreach($toclean->linkedObjects as $type_object => $linked_object) {
|
||||
foreach($linked_object as $toclean2clean) {
|
||||
$this->cleanObjectDatas($toclean2clean);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return $toclean;
|
||||
}
|
||||
@ -453,7 +488,7 @@ function cleanObjectDatas($toclean)
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
* @param object $toclean Object to clean
|
||||
* @param Object $toclean Object to clean
|
||||
* @return Object Object with cleaned properties
|
||||
*/
|
||||
function cleanAgendaEventsDatas($toclean)
|
||||
|
||||
@ -1851,8 +1851,11 @@ class Thirdparties extends DolibarrApi
|
||||
if (!DolibarrApiAccess::$user->rights->societe->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
|
||||
if ($rowid == 0) {
|
||||
$result = $this->company->initAsSpecimen();
|
||||
} else {
|
||||
$result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'Thirdparty not found');
|
||||
}
|
||||
|
||||
@ -3765,6 +3765,7 @@ class Societe extends CommonObject
|
||||
|
||||
// Initialize parameters
|
||||
$this->id = 0;
|
||||
$this->entity = 1;
|
||||
$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog');
|
||||
$this->nom = $this->name; // For backward compatibility
|
||||
$this->ref_ext = 'Ref ext';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -108,7 +108,7 @@ class Ticket extends CommonObject
|
||||
|
||||
/**
|
||||
* @var int Ticket statut
|
||||
* @deprecated
|
||||
* @deprecated
|
||||
*/
|
||||
public $fk_statut;
|
||||
|
||||
@ -197,6 +197,9 @@ class Ticket extends CommonObject
|
||||
*/
|
||||
public $notify_tiers_at_create;
|
||||
|
||||
/**
|
||||
* @var string msgid
|
||||
*/
|
||||
public $email_msgid;
|
||||
|
||||
public $lines;
|
||||
@ -1076,7 +1079,7 @@ class Ticket extends CommonObject
|
||||
* Initialise object with example values
|
||||
* Id must be 0 if object instance is a specimen
|
||||
*
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function initAsSpecimen()
|
||||
{
|
||||
@ -1101,6 +1104,7 @@ class Ticket extends CommonObject
|
||||
$this->date_read = '';
|
||||
$this->date_close = '';
|
||||
$this->tms = '';
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -153,13 +153,16 @@ class Users extends DolibarrApi
|
||||
//if (!DolibarrApiAccess::$user->rights->user->user->lire) {
|
||||
//throw new RestException(401);
|
||||
//}
|
||||
|
||||
$result = $this->useraccount->fetch($id);
|
||||
if ($id == 0) {
|
||||
$result = $this->useraccount->initAsSpecimen();
|
||||
} else {
|
||||
$result = $this->useraccount->fetch($id);
|
||||
}
|
||||
if (!$result) {
|
||||
throw new RestException(404, 'User not found');
|
||||
}
|
||||
|
||||
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
|
||||
if ($id > 0 && !DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
@ -286,11 +289,11 @@ class Users extends DolibarrApi
|
||||
//}
|
||||
// check mandatory fields
|
||||
/*if (!isset($request_data["login"]))
|
||||
throw new RestException(400, "login field missing");
|
||||
if (!isset($request_data["password"]))
|
||||
throw new RestException(400, "password field missing");
|
||||
if (!isset($request_data["lastname"]))
|
||||
throw new RestException(400, "lastname field missing");*/
|
||||
throw new RestException(400, "login field missing");
|
||||
if (!isset($request_data["password"]))
|
||||
throw new RestException(400, "password field missing");
|
||||
if (!isset($request_data["lastname"]))
|
||||
throw new RestException(400, "lastname field missing");*/
|
||||
//assign field values
|
||||
foreach ($request_data as $field => $value) {
|
||||
$this->useraccount->$field = $value;
|
||||
@ -327,9 +330,10 @@ class Users extends DolibarrApi
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
foreach ($request_data as $field => $value)
|
||||
{
|
||||
if ($field == 'id') continue;
|
||||
foreach ($request_data as $field => $value) {
|
||||
if ($field == 'id') {
|
||||
continue;
|
||||
}
|
||||
// The status must be updated using setstatus() because it
|
||||
// is not handled by the update() method.
|
||||
if ($field == 'statut') {
|
||||
@ -461,7 +465,9 @@ class Users extends DolibarrApi
|
||||
$sql = "SELECT t.rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t";
|
||||
$sql .= ' WHERE t.entity IN ('.getEntity('user').')';
|
||||
if ($group_ids) $sql .= " AND t.rowid IN (".$group_ids.")";
|
||||
if ($group_ids) {
|
||||
$sql .= " AND t.rowid IN (".$group_ids.")";
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters) {
|
||||
if (!DolibarrApi::_checkFilters($sqlfilters)) {
|
||||
@ -483,13 +489,11 @@ class Users extends DolibarrApi
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
$i = 0;
|
||||
$num = $this->db->num_rows($result);
|
||||
$min = min($num, ($limit <= 0 ? $num : $limit));
|
||||
while ($i < $min)
|
||||
{
|
||||
while ($i < $min) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$group_static = new UserGroup($this->db);
|
||||
if ($group_static->fetch($obj->rowid)) {
|
||||
@ -562,8 +566,8 @@ class Users extends DolibarrApi
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
* @param Object $object Object to clean
|
||||
* @return Object Object with cleaned properties
|
||||
* @param Object $object Object to clean
|
||||
* @return Object Object with cleaned properties
|
||||
*/
|
||||
protected function _cleanObjectDatas($object)
|
||||
{
|
||||
@ -681,8 +685,9 @@ class Users extends DolibarrApi
|
||||
{
|
||||
$account = array();
|
||||
foreach (Users::$FIELDS as $field) {
|
||||
if (!isset($data[$field]))
|
||||
if (!isset($data[$field])) {
|
||||
throw new RestException(400, "$field field missing");
|
||||
}
|
||||
$account[$field] = $data[$field];
|
||||
}
|
||||
return $account;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -93,14 +93,13 @@ class ZapierApi extends DolibarrApi
|
||||
* Get list of possibles choices for module
|
||||
*
|
||||
* Return an array with hook informations
|
||||
* @param integer $id ID
|
||||
*
|
||||
* @return array|mixed data
|
||||
* @return array data
|
||||
*
|
||||
* @url GET /getmoduleschoices/
|
||||
* @throws RestException
|
||||
*/
|
||||
public function getModulesChoices($id)
|
||||
public function getModulesChoices()
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->rights->zapier->read) {
|
||||
throw new RestException(401);
|
||||
@ -110,6 +109,7 @@ class ZapierApi extends DolibarrApi
|
||||
'orders' => 'Orders',
|
||||
'thirdparties' => 'Thirparties',
|
||||
'contacts' => 'Contacts',
|
||||
'users' => 'Users',
|
||||
);
|
||||
// $result = $this->hook->fetch($id);
|
||||
// if (! $result ) {
|
||||
@ -244,6 +244,7 @@ class ZapierApi extends DolibarrApi
|
||||
$fields = array(
|
||||
'url',
|
||||
);
|
||||
dol_syslog("API Zapier create hook receive : " . print_r($request_data, true), LOG_DEBUG);
|
||||
$result = $this->validate($request_data, $fields);
|
||||
|
||||
foreach ($request_data as $field => $value) {
|
||||
|
||||
@ -126,7 +126,7 @@ class Hook extends CommonObject
|
||||
),
|
||||
'module' => array(
|
||||
'type' => 'varchar(128)',
|
||||
'label' => 'Url',
|
||||
'label' => 'Module',
|
||||
'enabled' => 1,
|
||||
'visible' => 1,
|
||||
'position' => 30,
|
||||
@ -137,7 +137,7 @@ class Hook extends CommonObject
|
||||
),
|
||||
'action' => array(
|
||||
'type' => 'varchar(128)',
|
||||
'label' => 'Url',
|
||||
'label' => 'Action',
|
||||
'enabled' => 1,
|
||||
'visible' => 1,
|
||||
'position' => 30,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user