Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Memorekall Member New
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rekall
Memorekall Member New
Commits
7a7350f5
Commit
7a7350f5
authored
3 years ago
by
Camille Simiand
Browse files
Options
Downloads
Patches
Plain Diff
Refacto
parent
bfab37af
No related branches found
No related tags found
1 merge request
!45
tuleap-81-allow-a-new-user-to-access-the-capsule-edition-mode
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Controller/CapsuleEditorController.php
+123
-103
123 additions, 103 deletions
src/Controller/CapsuleEditorController.php
with
123 additions
and
103 deletions
src/Controller/CapsuleEditorController.php
+
123
−
103
View file @
7a7350f5
...
@@ -8,6 +8,9 @@ use App\Entity\CapsulePendingEditor;
...
@@ -8,6 +8,9 @@ use App\Entity\CapsulePendingEditor;
use
App\Entity\User
;
use
App\Entity\User
;
use
App\Form\CapsuleEditorsFormType
;
use
App\Form\CapsuleEditorsFormType
;
use
App\Repository\CapsulePendingEditorRepository
;
use
App\Repository\CapsulePendingEditorRepository
;
use
App\Repository\CapsuleRepository
;
use
App\Repository\UserRepository
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Symfony\Bridge\Twig\Mime\TemplatedEmail
;
use
Symfony\Bridge\Twig\Mime\TemplatedEmail
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
...
@@ -20,11 +23,19 @@ class CapsuleEditorController extends AbstractController
...
@@ -20,11 +23,19 @@ class CapsuleEditorController extends AbstractController
{
{
private
TranslatorInterface
$translator
;
private
TranslatorInterface
$translator
;
private
MailerInterface
$mailer
;
private
MailerInterface
$mailer
;
private
CapsulePendingEditorRepository
$capsule_pending_editor_repository
;
public
function
__construct
(
MailerInterface
$mailer
,
TranslatorInterface
$translator
)
private
EntityManagerInterface
$entity_manager
;
{
public
function
__construct
(
MailerInterface
$mailer
,
TranslatorInterface
$translator
,
CapsulePendingEditorRepository
$capsule_pending_editor_repository
,
EntityManagerInterface
$entity_manager
)
{
$this
->
mailer
=
$mailer
;
$this
->
mailer
=
$mailer
;
$this
->
translator
=
$translator
;
$this
->
translator
=
$translator
;
$this
->
capsule_pending_editor_repository
=
$capsule_pending_editor_repository
;
$this
->
entity_manager
=
$entity_manager
;
}
}
/**
/**
...
@@ -33,21 +44,15 @@ class CapsuleEditorController extends AbstractController
...
@@ -33,21 +44,15 @@ class CapsuleEditorController extends AbstractController
public
function
editCapsuleEditors
(
public
function
editCapsuleEditors
(
Request
$request
,
Request
$request
,
int
$capsule_id
,
int
$capsule_id
,
CapsulePendingEditorRepository
$capsule_pending_editor_repository
CapsuleRepository
$capsule_repository
,
UserRepository
$user_repository
):
Response
{
):
Response
{
$current_user
=
$this
->
getUser
();
$current_user
=
$this
->
getUser
();
if
(
!
$current_user
instanceof
User
)
{
if
(
!
$current_user
instanceof
User
)
{
return
$this
->
redirectToRoute
(
'app_logout'
);
return
$this
->
redirectToRoute
(
'app_logout'
);
}
}
$form
=
$this
->
createForm
(
CapsuleEditorsFormType
::
class
);
$form
->
handleRequest
(
$request
);
$entity_manager
=
$this
->
getDoctrine
()
->
getManager
();
$capsule_repository
=
$entity_manager
->
getRepository
(
Capsule
::
class
);
$capsule
=
$capsule_repository
->
find
(
$capsule_id
);
$capsule
=
$capsule_repository
->
find
(
$capsule_id
);
if
(
!
$capsule
)
{
if
(
!
$capsule
)
{
throw
$this
->
createNotFoundException
(
throw
$this
->
createNotFoundException
(
'No capsule found for id '
.
$capsule_id
'No capsule found for id '
.
$capsule_id
...
@@ -55,7 +60,6 @@ class CapsuleEditorController extends AbstractController
...
@@ -55,7 +60,6 @@ class CapsuleEditorController extends AbstractController
}
}
$current_capsule_editors_users
=
$capsule
->
getEditors
()
->
toArray
();
$current_capsule_editors_users
=
$capsule
->
getEditors
()
->
toArray
();
if
(
!
in_array
(
$current_user
,
$current_capsule_editors_users
))
{
if
(
!
in_array
(
$current_user
,
$current_capsule_editors_users
))
{
$this
->
addFlash
(
$this
->
addFlash
(
'warning'
,
'warning'
,
...
@@ -70,17 +74,45 @@ class CapsuleEditorController extends AbstractController
...
@@ -70,17 +74,45 @@ class CapsuleEditorController extends AbstractController
return
$this
->
redirectToRoute
(
'capsule_list'
);
return
$this
->
redirectToRoute
(
'capsule_list'
);
}
}
$
pending_edit
or
s
=
$
capsule_pending_editor_repository
->
findBy
([
'capsule_id'
=>
$capsule_id
]
);
$
f
or
m
=
$
this
->
createForm
(
CapsuleEditorsFormType
::
class
);
$
pending_editors_emails
=
$capsule_pending_editor_repository
->
getPendingEditorsEmails
(
$capsule_id
);
$
form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$editor_email
=
$form
->
get
(
'email'
)
->
getData
();
$editor_email
=
$form
->
get
(
'email'
)
->
getData
();
$user_associated_with_email_address
=
$user_repository
$user_associated_with_email_address
=
$entity_manager
->
getRepository
(
User
::
class
)
->
findOneBy
([
'email'
=>
$editor_email
]);
->
findOneBy
([
'email'
=>
$editor_email
]);
if
(
!
$user_associated_with_email_address
instanceof
User
)
{
if
(
!
$user_associated_with_email_address
instanceof
User
)
{
$this
->
addPendingEditor
(
$editor_email
,
$capsule
,
$current_user
);
}
else
{
$this
->
addEditor
(
$editor_email
,
$capsule
,
$current_user
,
$user_associated_with_email_address
,
$current_capsule_editors_users
);
}
return
$this
->
redirectToRoute
(
'edit_capsule_editors'
,
[
'capsule_id'
=>
$capsule_id
]);
}
$pending_editors
=
$this
->
capsule_pending_editor_repository
->
findBy
([
'capsule_id'
=>
$capsule_id
]);
return
$this
->
render
(
'capsule/editors/list_editors.html.twig'
,
[
'userPermissionsCapsuleForm'
=>
$form
->
createView
(),
'capsule_name'
=>
$capsule
->
getName
(),
'editors'
=>
$current_capsule_editors_users
,
'pending_editors'
=>
$pending_editors
]);
}
private
function
addPendingEditor
(
string
$editor_email
,
Capsule
$capsule
,
User
$current_user
):
void
{
$pending_editors_emails
=
$this
->
capsule_pending_editor_repository
->
getPendingEditorsEmails
(
$capsule
->
getId
());
if
(
in_array
(
$editor_email
,
$pending_editors_emails
))
{
if
(
in_array
(
$editor_email
,
$pending_editors_emails
))
{
$this
->
addFlash
(
$this
->
addFlash
(
'warning'
,
'warning'
,
...
@@ -91,17 +123,14 @@ class CapsuleEditorController extends AbstractController
...
@@ -91,17 +123,14 @@ class CapsuleEditorController extends AbstractController
]
]
)
)
);
);
return
;
return
$this
->
redirectToRoute
(
'edit_capsule_editors'
,
[
'capsule_id'
=>
$capsule_id
]);
}
}
$pending_editor
=
new
CapsulePendingEditor
();
$pending_editor
=
new
CapsulePendingEditor
();
$pending_editor
->
setCapsuleId
(
$capsule
_id
);
$pending_editor
->
setCapsuleId
(
$capsule
->
getId
()
);
$pending_editor
->
setEmail
(
$editor_email
);
$pending_editor
->
setEmail
(
$editor_email
);
$entity_manager
->
persist
(
$pending_editor
);
$
this
->
entity_manager
->
persist
(
$pending_editor
);
$entity_manager
->
flush
();
$
this
->
entity_manager
->
flush
();
$email
=
(
new
TemplatedEmail
())
$email
=
(
new
TemplatedEmail
())
->
to
(
$editor_email
)
->
to
(
$editor_email
)
...
@@ -123,12 +152,18 @@ class CapsuleEditorController extends AbstractController
...
@@ -123,12 +152,18 @@ class CapsuleEditorController extends AbstractController
]
]
)
)
);
);
return
$this
->
redirectToRoute
(
'edit_capsule_editors'
,
[
'capsule_id'
=>
$capsule_id
]);
}
}
/**
* @param array<User> $current_capsule_editors_users
*/
private
function
addEditor
(
string
$editor_email
,
Capsule
$capsule
,
User
$current_user
,
User
$user_associated_with_email_address
,
array
$current_capsule_editors_users
):
void
{
if
(
in_array
(
$user_associated_with_email_address
,
$current_capsule_editors_users
))
{
if
(
in_array
(
$user_associated_with_email_address
,
$current_capsule_editors_users
))
{
$this
->
addFlash
(
$this
->
addFlash
(
'warning'
,
'warning'
,
...
@@ -139,16 +174,13 @@ class CapsuleEditorController extends AbstractController
...
@@ -139,16 +174,13 @@ class CapsuleEditorController extends AbstractController
]
]
)
)
);
);
return
;
return
$this
->
redirectToRoute
(
'edit_capsule_editors'
,
[
'capsule_id'
=>
$capsule_id
]);
}
}
$capsule_editor
=
new
CapsuleEditor
();
$capsule_editor
=
new
CapsuleEditor
();
$capsule_editor
->
setUserId
(
$user_associated_with_email_address
->
getId
());
$capsule_editor
->
setUserId
(
$user_associated_with_email_address
->
getId
());
$capsule_editor
->
setCapsuleId
(
$capsule
_id
);
$capsule_editor
->
setCapsuleId
(
$capsule
->
getId
()
);
$
entity_manager
->
persist
(
$capsule_editor
);
$this
->
entity_manager
->
persist
(
$capsule_editor
);
$
entity_manager
->
flush
();
$this
->
entity_manager
->
flush
();
$email
=
(
new
TemplatedEmail
())
$email
=
(
new
TemplatedEmail
())
->
to
(
$editor_email
)
->
to
(
$editor_email
)
...
@@ -171,17 +203,5 @@ class CapsuleEditorController extends AbstractController
...
@@ -171,17 +203,5 @@ class CapsuleEditorController extends AbstractController
]
]
)
)
);
);
return
$this
->
redirectToRoute
(
'edit_capsule_editors'
,
[
'capsule_id'
=>
$capsule_id
]);
}
return
$this
->
render
(
'capsule/editors/list_editors.html.twig'
,
[
'userPermissionsCapsuleForm'
=>
$form
->
createView
(),
'capsule_name'
=>
$capsule
->
getName
(),
'editors'
=>
$current_capsule_editors_users
,
'pending_editors'
=>
$pending_editors
]);
}
}
}
}
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