mirror of
https://github.com/tchapi/davis.git
synced 2025-03-19 12:00:00 +01:00
Add an isAdmin property for principals (1/2)
This commit is contained in:
parent
7650261b9f
commit
56a8fccb33
@ -79,12 +79,14 @@ class AdminController extends AbstractController
|
||||
|
||||
$form->get('displayName')->setData($principal->getDisplayName());
|
||||
$form->get('email')->setData($principal->getEmail());
|
||||
$form->get('isAdmin')->setData($principal->getIsAdmin());
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$displayName = $form->get('displayName')->getData();
|
||||
$email = $form->get('email')->getData();
|
||||
$isAdmin = $form->get('isAdmin')->getData();
|
||||
|
||||
// Create password for user
|
||||
if ($username && is_null($user->getPassword())) {
|
||||
@ -131,7 +133,8 @@ class AdminController extends AbstractController
|
||||
}
|
||||
|
||||
$principal->setDisplayName($displayName)
|
||||
->setEmail($email);
|
||||
->setEmail($email)
|
||||
->setIsAdmin($isAdmin);
|
||||
|
||||
$entityManager->persist($user);
|
||||
$entityManager->flush();
|
||||
|
@ -54,6 +54,12 @@ class Principal
|
||||
*/
|
||||
private $isMain;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $isAdmin;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Principal")
|
||||
* @ORM\JoinTable(
|
||||
@ -73,6 +79,7 @@ class Principal
|
||||
{
|
||||
$this->delegees = new ArrayCollection();
|
||||
$this->isMain = true;
|
||||
$this->isAdmin = false;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@ -173,4 +180,16 @@ class Principal
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsAdmin(): ?bool
|
||||
{
|
||||
return $this->isAdmin;
|
||||
}
|
||||
|
||||
public function setIsAdmin(bool $isAdmin): self
|
||||
{
|
||||
$this->isAdmin = $isAdmin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
@ -38,6 +39,12 @@ class UserType extends AbstractType
|
||||
'first_options' => ['label' => 'form.password'],
|
||||
'second_options' => ['label' => 'form.password.repeat'],
|
||||
])
|
||||
->add('isAdmin', CheckboxType::class, [
|
||||
'label' => 'form.admin',
|
||||
'help' => 'form.admin.help',
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
])
|
||||
->add('save', SubmitType::class, [
|
||||
'label' => 'save',
|
||||
]);
|
||||
|
@ -19,7 +19,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-1">{{ "users.username"|trans }} : <code>{{ principal.username }}</code></p>
|
||||
<small>{{ "users.uri"|trans }} : <code>{{ principal.uri }}</code></small>
|
||||
<small>{{ "users.uri"|trans }} : <code>{{ principal.uri }}</code>{% if principal.isAdmin %} — <span class="badge badge-primary">{{ "users.administrator"|trans }}</span>{% endif %}</small>
|
||||
<div class="btn-group btn-group-sm mt-3 d-flex d-lg-none" role="group">
|
||||
<a href="{{ path('calendars',{username: principal.username}) }}" class="btn btn-outline-secondary flex-fill w-100"><span class="d-none d-sm-inline">🗓 </span>{{ "users.calendars"|trans }}</a>
|
||||
<a href="{{ path('address_books',{username: principal.username})}}" class="btn btn-outline-secondary flex-fill w-100"><span class="d-none d-sm-inline">📖 </span>{{ "users.addressbooks"|trans }}</a>
|
||||
|
@ -177,6 +177,10 @@
|
||||
<source>users.uri</source>
|
||||
<target>Principal URI</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="Xq.ID4c" resname="users.administrator">
|
||||
<source>users.administrator</source>
|
||||
<target>Administrator</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="rzn9R3M" resname="users.calendars">
|
||||
<source>users.calendars</source>
|
||||
<target>Calendars</target>
|
||||
@ -253,6 +257,14 @@
|
||||
<source>form.email</source>
|
||||
<target>Email</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="_YeuWGA" resname="form.admin">
|
||||
<source>form.admin</source>
|
||||
<target>Is this user an administrator ?</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="hIz1KP1" resname="form.admin.help">
|
||||
<source>form.admin.help</source>
|
||||
<target>If checked, this user (namely, its principal) will be injected in every single ACL rule with the '{DAV:}all' privileges.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="k660.eC" resname="form.displayName">
|
||||
<source>form.displayName</source>
|
||||
<target>Display name</target>
|
||||
|
Loading…
x
Reference in New Issue
Block a user