Skip to content
Snippets Groups Projects
Commit d0cd0572 authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3440344 by eiriksm: Make it possible to see but not use invite form as non admin

parent 659086c5
No related branches found
No related tags found
1 merge request!44Make for prettier and show things even if no access
Pipeline #144226 passed with warnings
......@@ -3,8 +3,7 @@
namespace Drupal\violinist_teams\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\violinist_teams\TeamNode;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -14,17 +13,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
final class MembersController extends ControllerBase {
public function __construct(
private EntityTypeManagerInterface $entity_type_manager,
private ModuleHandlerInterface $module_handler) {}
/**
* The actual constructor for this controller.
*/
public function __construct(AccountProxyInterface $currentUser) {
$this->currentUser = $currentUser;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('current_user')
);
}
......@@ -34,18 +35,11 @@ final class MembersController extends ControllerBase {
public function build(TeamNode $team) {
$build = [];
$build['invite'] = [
'#type' => 'link',
'#title' => $this->t('Invite users via link'),
'#url' => Url::fromRoute('violinist_teams.team_members_invite', [
'team' => $team->id(),
]),
'#attributes' => [
'class' => [
'btn',
'btn-success',
'use-ajax',
],
'data-dialog-type' => 'modal',
'#theme' => 'violinist_teams_invite_link_wrapper',
'#link_element' => [
'#theme' => 'violinist_teams_invite_link_or_access_notice',
'#link_href' => Url::fromRoute('violinist_teams.team_members_invite', ['team' => $team->id()])->toString(),
'#invite_access' => $team->isAdmin($this->currentUser),
],
];
// Then let's also show a table of all the users, and the status they have.
......
{% if access %}
<a href="{{ link }}"
class="btn use-ajax flex items-center justify-center px-4 py-2 text-sm font-medium" data-dialog-type="modal">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3.5 w-3.5 mr-2 -ml-1" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path
d="M8 9a3 3 0 100-6 3 3 0 000 6zM8 11a6 6 0 016 6H2a6 6 0 016-6zM16 7a1 1 0 10-2 0v1h-1a1 1 0 100 2h1v1a1 1 0 102 0v-1h1a1 1 0 100-2h-1V7z"/>
</svg>
Invite users via link
</a>
{% else %}
<button disabled="disabled"
class="w-full opacity-50 btn hover:bg-gray-400 btn bg-gray-400 flex items-center justify-center px-4 py-2 text-sm font-medium cursor-not-allowed">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3.5 w-3.5 mr-2 -ml-1" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path
d="M8 9a3 3 0 100-6 3 3 0 000 6zM8 11a6 6 0 016 6H2a6 6 0 016-6zM16 7a1 1 0 10-2 0v1h-1a1 1 0 100 2h1v1a1 1 0 102 0v-1h1a1 1 0 100-2h-1V7z"/>
</svg>
Invite users via link
</button>
<p>
<span class="text-red-900">You don't have permission to invite users. Please contact an admin of the team.</span>
</p>
{% endif %}
<div class="md:grid-cols-12 grid my-5">
<div class="col-span-3"></div>
<div class="md:col-span-6">
<div class="relative overflow-hidden bg-white border-2 p-10 dark:bg-gray-800">
<div class="flex-row items-center justify-between py-4 space-y-3 sm:flex sm:space-y-0 sm:space-x-4">
<div>
<h5 class="mr-3 font-semibold dark:text-white">Invite users</h5>
<p>
You can invite new users to your organization by generating an invite link. You can add as many internal or external users as you want.
</p>
</div>
</div>
{{ link_element }}
</div>
</div>
<div></div>
</div>
......@@ -14,6 +14,17 @@ use Drupal\violinist_teams\TeamNode;
*/
function violinist_teams_theme($existing, $type, $theme, $path) {
return [
'violinist_teams_invite_link_wrapper' => [
'variables' => [
'link_element' => '',
],
],
'violinist_teams_invite_link_or_access_notice' => [
'variables' => [
'link_href' => '',
'invite_access' => FALSE,
],
],
'violinist_teams_invite_link_textfield' => [
'variables' => [
'link' => '',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment