Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gleap
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
gleap
Commits
308cc7ef
Commit
308cc7ef
authored
1 year ago
by
Yazan Majadba
Committed by
Qusai Taha
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3406765
: Add enabling mode
parent
69033763
Branches
1.0.x
Tags
1.0.0-alpha5
1 merge request
!1
Issue #3406765: Add enabling mode
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Form/GleapConfiguration.php
+29
-0
29 additions, 0 deletions
src/Form/GleapConfiguration.php
src/Plugin/Block/GleapBlock.php
+17
-0
17 additions, 0 deletions
src/Plugin/Block/GleapBlock.php
with
46 additions
and
0 deletions
src/Form/GleapConfiguration.php
+
29
−
0
View file @
308cc7ef
...
...
@@ -34,13 +34,40 @@ class GleapConfiguration extends ConfigFormBase {
// Default settings.
$config
=
$this
->
config
(
'gleap.gleap_configuration'
);
// Gleap enable.
$form
[
'gleap_enable'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Enable Gleap'
),
'#default_value'
=>
$config
->
get
(
'gleap_enable'
),
'#description'
=>
$this
->
t
(
'Check this box if you want to enable Gleap. Uncheck to disable Gleap.'
),
];
$states
=
[
'visible'
=>
[
':input[name='
.
'gleap_enable'
.
']'
=>
[
'checked'
=>
TRUE
]],
];
// Gleap API key.
$form
[
'gleap_api_key'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Gleap API key'
),
'#default_value'
=>
$config
->
get
(
'gleap_api_key'
),
'#description'
=>
$this
->
t
(
'Give your gleap API key.'
),
'#states'
=>
$states
,
'#required'
=>
TRUE
,
];
$roles
=
[];
foreach
(
$roles
=
Role
::
loadMultiple
()
as
$role
)
{
$roles
[
$role
->
id
()]
=
$role
->
get
(
'label'
);
}
$form
[
'gleap_roles'
]
=
[
'#type'
=>
'checkboxes'
,
'#title'
=>
$this
->
t
(
'Enable Gleap for roles:'
),
'#options'
=>
$roles
,
'#default_value'
=>
$config
->
get
(
'gleap_roles'
),
'#required'
=>
TRUE
,
'#states'
=>
$states
,
];
return
parent
::
buildForm
(
$form
,
$form_state
);
...
...
@@ -52,6 +79,8 @@ class GleapConfiguration extends ConfigFormBase {
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$config
=
$this
->
config
(
'gleap.gleap_configuration'
);
$config
->
set
(
'gleap_api_key'
,
$form_state
->
getValue
(
'gleap_api_key'
));
$config
->
set
(
'gleap_enable'
,
$form_state
->
getValue
(
'gleap_enable'
));
$config
->
set
(
'gleap_roles'
,
$form_state
->
getValue
(
'gleap_roles'
));
$config
->
save
();
return
parent
::
submitForm
(
$form
,
$form_state
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Block/GleapBlock.php
+
17
−
0
View file @
308cc7ef
...
...
@@ -13,6 +13,7 @@ use Drupal\Core\Session\AccountInterface;
use
Drupal\Core\Messenger\MessengerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Access\AccessResult
;
/**
* Provides a Gleap block.
...
...
@@ -88,6 +89,10 @@ class GleapBlock extends BlockBase implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public
function
build
():
array
{
if
(
!
$this
->
configFactory
->
get
(
'gleap_enable'
))
{
return
[];
}
if
(
empty
(
$this
->
configFactory
->
get
(
'gleap_api_key'
))
&&
(
$this
->
currentUser
->
hasPermission
(
'administer gleap'
)))
{
$url
=
Url
::
fromUri
(
'route:gleap_configuration'
);
$link
=
new
Link
(
$this
->
t
(
'here'
),
$url
);
...
...
@@ -102,6 +107,18 @@ class GleapBlock extends BlockBase implements ContainerFactoryPluginInterface {
];
}
/**
* {@inheritdoc}
*/
protected
function
blockAccess
(
AccountInterface
$account
)
{
$current_roles
=
$this
->
currentUser
->
getRoles
();
if
(
!
empty
(
array_intersect
(
$current_roles
,
$this
->
configFactory
->
get
(
'gleap_roles'
))))
{
return
AccessResult
::
allowed
();
}
else
{
return
AccessResult
::
forbidden
();
}
}
/**
* {@inheritdoc}
*/
...
...
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