Skip to content

Commit

Permalink
Added option in general settings: Permission control for viewing answ…
Browse files Browse the repository at this point in the history
…ers and votes
  • Loading branch information
Jefferson49 committed Feb 2, 2024
1 parent 7f5b8a8 commit 688706a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
2 changes: 2 additions & 0 deletions com_sexypolling/admin/access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.view.answers" title="COM_SEXYPOLLING_ACTION_VIEW_ANSWERS" description="COM_SEXYPOLLING_ACTION_VIEW_ANSWERS_COMPONENT_DESC" />
<action name="core.view.votes" title="COM_SEXYPOLLING_ACTION_VIEW_VOTES" description="COM_SEXYPOLLING_ACTION_VIEW_VOTES_COMPONENT_DESC" />
</section>
</access>
20 changes: 18 additions & 2 deletions com_sexypolling/admin/config.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset
name="general"
label="COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_LABEL"
description="COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_DESC"
addfieldprefix="Joomla\Component\SexyPolling\Administrator\Field"
>
<field
name="permission_control_for_answers_and_votes"
type="radio"
layout="joomla.form.field.radio.switcher"
label="COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_LABEL"
description="COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_DESC"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>

<fieldset
name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
description="JCONFIG_PERMISSIONS_DESC"
>

<field
name="rules"
type="rules"
Expand All @@ -17,7 +34,6 @@
component="com_sexypolling"
section="component"
/>

</fieldset>

</config>
14 changes: 13 additions & 1 deletion com_sexypolling/admin/language/de-DE/de-DE.com_sexypolling.ini
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,16 @@ COM_SEXYPOLLING_USER="Benutzer"
COM_SEXYPOLLING_IP="IP"
COM_SEXYPOLLING_COUNTRY="Land"
COM_SEXYPOLLING_CITY="Stadt"
COM_SEXYPOLLING_REGION="Region"
COM_SEXYPOLLING_REGION="Region"

COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_LABEL="Allgemein"
COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_DESC="Allgemeine Einstellungen"
COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_LABEL="Berechtigung für die Anzeige von Antworten und Stimmen"
COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_DESC="Aktivieren der Berechtigung zum Anzeigen von Antworten und Stimmen. Diese Einstellung erlaubt eine striktere Handhabung der Berechtigungen für Antworten/Stimmen, z.B. wenn eine Umfrage für eine Wahl genutzt wird. Berechtigungen können für jede Benutzergruppe in den Einstellungen für Berechtigungen vorgenommen werden."

COM_SEXYPOLLING_ACTION_VIEW_ANSWERS="Anzeigen von Antworten"
COM_SEXYPOLLING_ACTION_VIEW_ANSWERS_COMPONENT_DESC="Berechtigung zur Anzeige von Antworten im Backend. Nur relevant, wenn die Berechtigung für die Anzeige von Antworten/Stimmen in den allgemeinen Einstellungen aktiviert ist."
COM_SEXYPOLLING_ACTION_VIEW_ANSWERS_NO_PERMISSION="Sie haben nicht die erforderliche Berechtigung, um Antworten anzuzeigen."
COM_SEXYPOLLING_ACTION_VIEW_VOTES="Anzeigen von Stimmen"
COM_SEXYPOLLING_ACTION_VIEW_VOTES_COMPONENT_DESC="Berechtigung zur Anzeige von Stimmen im Backend. Nur relevant, wenn die Berechtigung für die Anzeige von Antworten/Stimmen in den allgemeinen Einstellungen aktiviert ist."
COM_SEXYPOLLING_ACTION_VIEW_VOTES_NO_PERMISSION="Sie haben nicht die erforderliche Berechtigung, um Stimmen anzuzeigen."
12 changes: 12 additions & 0 deletions com_sexypolling/admin/language/en-GB/en-GB.com_sexypolling.ini
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ COM_SEXYPOLLING_UP="Up"
COM_SEXYPOLLING_DOWN="Down"
COM_SEXYPOLLING_CUSTOM_STYLES="Custom Styles"
COM_SEXYPOLLING_SEXY_TEMPLATE="Sexy Template"

COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_LABEL="General"
COM_SEXYPOLLING_CONFIG_GENERAL_SETTINGS_DESC="General settings"
COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_LABEL="Permission control for viewing answers and votes"
COM_SEXYPOLLING_CONFIG_PERMISSION_CONTROL_FOR_ANSWERS_AND_VOTES_DESC="Activate permission control for viewing answers and votes. This allows to establish stricter permission handling for answers/votes, e.g. if a poll is used for elections. Permissions can be set for each user group in the permissions settings."

COM_SEXYPOLLING_ACTION_VIEW_ANSWERS="View answers"
COM_SEXYPOLLING_ACTION_VIEW_ANSWERS_COMPONENT_DESC="Permission, wether answers are shown in the administration backend. Only relevant if permission control for viewing answers/votes is activated in general settings."
COM_SEXYPOLLING_ACTION_VIEW_ANSWERS_NO_PERMISSION="You do not have the permission to view answers"
COM_SEXYPOLLING_ACTION_VIEW_VOTES="View votes"
COM_SEXYPOLLING_ACTION_VIEW_VOTES_COMPONENT_DESC="Permission, wether votes are shown in the administration backend. Only relevant if permission control for viewing answers/votes is activated in general settings."
COM_SEXYPOLLING_ACTION_VIEW_VOTES_NO_PERMISSION="You do not have the permission to view votes"
22 changes: 22 additions & 0 deletions com_sexypolling/admin/views/sexyanswers/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @todo Use of $this in global code might be unatended
*/

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
Expand All @@ -43,6 +45,22 @@
HTMLHelper::_('sortablelist.sortable', 'articleList', 'adminForm', strtolower($listDirn ?? ''), $saveOrderingUrl);
}
$sortFields = $this->getSortFields();

$application = Factory::getApplication();
$user = $application->getIdentity();

if ($application->isClient('site')) {
$params = $application->getParams('com_sexypolling');
} else {
$params = ComponentHelper::getParams('com_sexypolling');
}

//if permission control for answers is activated, use permission settings for viewing answers
if ($params->get('permission_control_for_answers_and_votes', 0)) {
$show_answers = $user !== null && $user->authorise('core.view.answers', 'com_sexypolling');
} else {
$show_answers = true;
}
?>
<script type="text/javascript">
Joomla.orderTable = function() {
Expand All @@ -66,6 +84,9 @@
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<?php if(!$show_answers): ?>
<h3 style="color: red;"><?php echo Text::_('COM_SEXYPOLLING_ACTION_VIEW_VOTES_NO_PERMISSION');?></h3>
<?php else : ?>
<div id="filter-bar" class="btn-toolbar">
<div class="filter-search btn-group pull-left">
<label for="filter_search" class="element-invisible"><?php echo Text::_('COM_SEXYPOLLING_SEARCH_BY_NAME');?></label>
Expand Down Expand Up @@ -189,4 +210,5 @@

<?php include (JPATH_BASE.'/components/com_sexypolling/helpers/footer.php'); ?>
</div>
<?php endif;?>
</form>
22 changes: 22 additions & 0 deletions com_sexypolling/admin/views/sexyvotes/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @todo Use of $this in global code might be unatended
*/

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
Expand All @@ -39,6 +41,22 @@
$archived = $this->state->get('filter.published') == 2 ? true : false;
$trashed = $this->state->get('filter.published') == -2 ? true : false;
$sortFields = $this->getSortFields();

$application = Factory::getApplication();
$user = $application->getIdentity();

if ($application->isClient('site')) {
$params = $application->getParams('com_sexypolling');
} else {
$params = ComponentHelper::getParams('com_sexypolling');
}

//if permission control for answers is activated, use permission settings for viewing answers
if ($params->get('permission_control_for_answers_and_votes', 0)) {
$show_answers = $user !== null && $user->authorise('core.view.votes', 'com_sexypolling');
} else {
$show_answers = true;
}
?>
<script type="text/javascript">
Joomla.orderTable = function() {
Expand All @@ -62,6 +80,9 @@
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<?php if(!$show_answers): ?>
<h3 style="color: red;"><?php echo Text::_('COM_SEXYPOLLING_ACTION_VIEW_VOTES_NO_PERMISSION');?></h3>
<?php else : ?>
<div id="filter-bar" class="btn-toolbar">
<div class="filter-search btn-group pull-left">
<label for="filter_search" class="element-invisible"><?php echo Text::_('COM_SEXYPOLLING_SEARCH');?></label>
Expand Down Expand Up @@ -187,4 +208,5 @@

<?php include (JPATH_BASE.'/components/com_sexypolling/helpers/footer.php'); ?>
</div>
<?php endif;?>
</form>

0 comments on commit 688706a

Please sign in to comment.