Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
fb89f98e
Verified
Commit
fb89f98e
authored
5 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #12509 TIME 0:30 Enable/suspend contact
parent
3d64b21d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rest/index.php
+1
-0
1 addition, 0 deletions
rest/index.php
src/app/contact/controllers/ContactController.php
+75
-16
75 additions, 16 deletions
src/app/contact/controllers/ContactController.php
with
76 additions
and
16 deletions
rest/index.php
+
1
−
0
View file @
fb89f98e
...
@@ -117,6 +117,7 @@ $app->post('/contacts', \Contact\controllers\ContactController::class . ':create
...
@@ -117,6 +117,7 @@ $app->post('/contacts', \Contact\controllers\ContactController::class . ':create
$app
->
get
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':getById'
);
$app
->
get
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':getById'
);
$app
->
put
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':update'
);
$app
->
put
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':update'
);
$app
->
delete
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':delete'
);
$app
->
delete
(
'/contacts/{id}'
,
\Contact\controllers\ContactController
::
class
.
':delete'
);
$app
->
put
(
'/contacts/{id}/activation'
,
\Contact\controllers\ContactController
::
class
.
':updateActivation'
);
$app
->
get
(
'/contacts/{contactId}/communication'
,
\Contact\controllers\ContactController
::
class
.
':getCommunicationByContactId'
);
$app
->
get
(
'/contacts/{contactId}/communication'
,
\Contact\controllers\ContactController
::
class
.
':getCommunicationByContactId'
);
$app
->
get
(
'/contactsGroups'
,
\Contact\controllers\ContactGroupController
::
class
.
':get'
);
$app
->
get
(
'/contactsGroups'
,
\Contact\controllers\ContactGroupController
::
class
.
':get'
);
...
...
This diff is collapsed.
Click to expand it.
src/app/contact/controllers/ContactController.php
+
75
−
16
View file @
fb89f98e
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
/**
/**
* @brief Contact Controller
* @brief Contact Controller
*
* @author dev@maarch.org
* @author dev@maarch.org
*/
*/
...
@@ -43,11 +42,12 @@ class ContactController
...
@@ -43,11 +42,12 @@ class ContactController
//TODO privileges
//TODO privileges
$body
=
$request
->
getParsedBody
();
$body
=
$request
->
getParsedBody
();
if
(
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'lastname'
])
&&
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'company'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname or company is mandatory'
]);
$control
=
ContactController
::
controlContact
([
'body'
=>
$body
]);
if
(
!
empty
(
$control
[
'errors'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
$control
[
'errors'
]]);
}
}
$body
[
'email'
]
=
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
?
$body
[
'email'
]
:
null
;
if
(
!
empty
(
$body
[
'email'
]))
{
if
(
!
empty
(
$body
[
'email'
]))
{
$contact
=
ContactModel
::
get
([
'select'
=>
[
'id'
],
'where'
=>
[
'email = ?'
],
'data'
=>
[
$body
[
'email'
]]]);
$contact
=
ContactModel
::
get
([
'select'
=>
[
'id'
],
'where'
=>
[
'email = ?'
],
'data'
=>
[
$body
[
'email'
]]]);
if
(
!
empty
(
$contact
[
0
][
'id'
]))
{
if
(
!
empty
(
$contact
[
0
][
'id'
]))
{
...
@@ -133,18 +133,18 @@ class ContactController
...
@@ -133,18 +133,18 @@ class ContactController
{
{
//TODO privileges
//TODO privileges
$body
=
$request
->
getParsedBody
();
$control
=
ContactController
::
controlContact
([
'body'
=>
$body
]);
if
(
!
empty
(
$control
[
'errors'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
$control
[
'errors'
]]);
}
$contact
=
ContactModel
::
getById
([
'id'
=>
$args
[
'id'
],
'select'
=>
[
1
]]);
$contact
=
ContactModel
::
getById
([
'id'
=>
$args
[
'id'
],
'select'
=>
[
1
]]);
if
(
empty
(
$contact
))
{
if
(
empty
(
$contact
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Contact does not exist'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Contact does not exist'
]);
}
}
$body
=
$request
->
getParsedBody
();
if
(
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'lastname'
])
&&
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'company'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body lastname or company is mandatory'
]);
}
$body
[
'email'
]
=
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
)
?
$body
[
'email'
]
:
null
;
if
(
!
empty
(
$body
[
'communicationMeans'
]))
{
if
(
!
empty
(
$body
[
'communicationMeans'
]))
{
if
(
filter_var
(
$body
[
'communicationMeans'
],
FILTER_VALIDATE_EMAIL
))
{
if
(
filter_var
(
$body
[
'communicationMeans'
],
FILTER_VALIDATE_EMAIL
))
{
$body
[
'communicationMeans'
]
=
[
'email'
=>
$body
[
'communicationMeans'
]];
$body
[
'communicationMeans'
]
=
[
'email'
=>
$body
[
'communicationMeans'
]];
...
@@ -166,11 +166,11 @@ class ContactController
...
@@ -166,11 +166,11 @@ class ContactController
'company'
=>
$body
[
'company'
]
??
null
,
'company'
=>
$body
[
'company'
]
??
null
,
'department'
=>
$body
[
'department'
]
??
null
,
'department'
=>
$body
[
'department'
]
??
null
,
'function'
=>
$body
[
'function'
]
??
null
,
'function'
=>
$body
[
'function'
]
??
null
,
'address_number'
=>
$body
[
'addressNumber'
]
??
null
,
'address_number'
=>
$body
[
'addressNumber'
]
??
null
,
'address_street'
=>
$body
[
'addressStreet'
]
??
null
,
'address_street'
=>
$body
[
'addressStreet'
]
??
null
,
'address_postcode'
=>
$body
[
'addressPostcode'
]
??
null
,
'address_postcode'
=>
$body
[
'addressPostcode'
]
??
null
,
'address_town'
=>
$body
[
'addressTown'
]
??
null
,
'address_town'
=>
$body
[
'addressTown'
]
??
null
,
'address_country'
=>
$body
[
'addressCountry'
]
??
null
,
'address_country'
=>
$body
[
'addressCountry'
]
??
null
,
'email'
=>
$body
[
'email'
]
??
null
,
'email'
=>
$body
[
'email'
]
??
null
,
'phone'
=>
$body
[
'phone'
]
??
null
,
'phone'
=>
$body
[
'phone'
]
??
null
,
'communication_means'
=>
!
empty
(
$body
[
'communicationMeans'
])
?
json_encode
(
$body
[
'communicationMeans'
])
:
null
,
'communication_means'
=>
!
empty
(
$body
[
'communicationMeans'
])
?
json_encode
(
$body
[
'communicationMeans'
])
:
null
,
...
@@ -185,6 +185,26 @@ class ContactController
...
@@ -185,6 +185,26 @@ class ContactController
return
$response
->
withStatus
(
204
);
return
$response
->
withStatus
(
204
);
}
}
public
function
updateActivation
(
Request
$request
,
Response
$response
,
array
$args
)
{
//TODO privileges
$contact
=
ContactModel
::
getById
([
'id'
=>
$args
[
'id'
],
'select'
=>
[
1
]]);
if
(
empty
(
$contact
))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Contact does not exist'
]);
}
$body
=
$request
->
getParsedBody
();
ContactModel
::
update
([
'set'
=>
[
'enabled'
=>
empty
(
$body
[
'enabled'
])
?
'false'
:
'true'
],
'where'
=>
[
'id = ?'
],
'data'
=>
[
$args
[
'id'
]]
]);
return
$response
->
withStatus
(
204
);
}
public
function
delete
(
Request
$request
,
Response
$response
,
array
$args
)
public
function
delete
(
Request
$request
,
Response
$response
,
array
$args
)
{
{
//TODO privileges
//TODO privileges
...
@@ -662,4 +682,43 @@ class ContactController
...
@@ -662,4 +682,43 @@ class ContactController
return
$contacts
;
return
$contacts
;
}
}
private
static
function
controlContact
(
array
$args
)
{
$body
=
$args
[
'body'
];
if
(
empty
(
$body
))
{
return
[
'errors'
=>
'Body is not set or empty'
];
}
elseif
(
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'lastname'
])
&&
!
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$body
[
'company'
]))
{
return
[
'errors'
=>
'Body lastname or company is mandatory'
];
}
elseif
(
!
empty
(
$body
[
'email'
])
&&
!
filter_var
(
$body
[
'email'
],
FILTER_VALIDATE_EMAIL
))
{
return
[
'errors'
=>
'Body email is not valid'
];
}
elseif
(
!
empty
(
$body
[
'phone'
])
&&
!
preg_match
(
"/\+?((|\ |\.|\(|\)|\-)?(\d)*)*\d$/"
,
$body
[
'phone'
]))
{
return
[
'errors'
=>
'Body phone is not valid'
];
}
$lengthFields
=
[
'civility'
,
'firstname'
,
'lastname'
,
'company'
,
'department'
,
'function'
,
'addressNumber'
,
'addressStreet'
,
'addressPostcode'
,
'addressTown'
,
'addressCountry'
,
'email'
,
'phone'
];
foreach
(
$lengthFields
as
$field
)
{
if
(
!
empty
(
$body
[
$field
])
&&
!
Validator
::
stringType
()
->
length
(
1
,
256
)
->
validate
(
$body
[
$field
]))
{
return
[
'errors'
=>
"Body
{
$field
}
length is not valid (1..256)"
];
}
}
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment