The default value for Manage site configuration is off
security > groups > content authors > permissions
Although it's possible to simply check the box and activate this, I would rather have this on by default for every SS installation.
How can the default value for this be set to on?
This should do as required, make an extension of Group and add a requireDefaultRecords function, this is called on every dev build.
This function is to look for that permission and if not existing create it...
class GroupExtension extends DataExtension {
function requireDefaultRecords() {
//get the content-authors group
if ($group = Group::get()->filter('Code','content-authors')->first()) {
//expected permission record content
$arrPermissionData = array(
'Arg' => 0,
'Type' => 1,
'Code' => 'EDIT_SITECONFIG',
'GroupID' => $group->ID
);
//if the permission is not found, then create it
if (!Permission::get()->filter($arrPermissionData)->first())
Permission::create($arrPermissionData)->write();
}
}
}
As ever to register the extension add this to your config.yml...
Group:
extensions:
- GroupExtension
Related
I am using Metronic 8 admin dashboard template for laravel.
The developer made the nav menu as array:
<?php
return array(
// Main menu
'main' => array(
//// Dashboard
array(
'title' => 'Dashboard',
'path' => '',
'icon' => theme()->getSvgIcon("demo1/media/icons/duotune/art/art002.svg", "svg-icon-2") ,
) ,
)
)
If you want to add a new nav item, just add an object inside the array.
I am currently using Spatie user roles & permissions. According to their docs, I can use blade directives like this:
#can('permission name')
test
#endcan
OR
#role('role name')
test
#endrole
Unfortunately, the menu.php is a plain php config file and not a blade.
How can I use spatie to hide nav items based on user role?
Resources:
Metronic laravel docs
Spatie docs
You need to change configs runtime, in Controller or in Middleware or even in Provider, depending on your needs. You need to do something like:
$navs = config('config.global.menu');
if(auth()->user()->can('permission name')){
$navs[] = 'nav item';
config([
'config.global.menu' => $navs
]);
}
You can create a new listener and bind Illuminate\Auth\Events\Login event to it in EventServiceProvider. I've named this event as ModifyMetronicMenu.
protected $listen = [
Login::class=>[
ModifyMetronicMenu::class
]
];
ModifyMetronicMenu listener
namespace App\Listeners;
class ModifyMetronicMenu
{
public function handle($event)
{
$newMenu = array_filter(config('menu.main'),function ($item){
return \Auth::user()->can(data_get($item,'title'));
});
// Update the menu config file
config(['menu.main'=>$newMenu]);
}
}
As you can see, I have filtered menu and have updated the config. Notice that the condition that I wrote in the array_filter is not correct and you should tune it base on your needs.
Is it possible to add a custom button that downloads pdf ?
ive tried doing it but i only get create button from this example: Link here
'searchInputs' => array(
1 => 'payment_date',
2 => 'payment_stage',
3 => 'or_no',
),
'create' =>
array(
'formBase' => 'PrintPayment.php',
'formBaseClass' => 'PrintPayment',
'getFormBodyParams' => array('', '', 'PrintPaymentSave'),
'createButton' => $mod_strings['LNK_NEW_PAYMENT']
),
is there any other way to add a download functionality ?
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/SugarObjects/forms/FormBase.php');
class PrintPayment extends FormBase {
var $moduleName = 'PrintPayment';
var $objectName = 'PrintPayment';
function handleSave($prefix, $redirect=true, $useRequired=false){
require_once('include/formbase.php');
$focus = new PrintPayment();
$focus = populateFromPost($prefix, $focus);
$focus->save();
}
}
is there any experts who knows this ? thanks in advance.
First you need to go to dropdown editor in admin panel and find "pdf_template_type_dom".
It's list responsible for modules available in PDF - templates module.
After adding module of your choice to the list you might need to rebuild the app.
After you add module, create a some template for it.
Afterwards you need to modify your viewdefs in your module to add the button allowing for PDF print. Here is custom code for the button:
array ( 'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');" value="PDF">'
Add the button somewhere and voila.
I tested in DetailView for my custom modules but the principle should be the same.
I'm using the tx_news extension for Typo3. Therefore I'd like to disable some settings that are not used on my page, for instance categories:
I've already disabled them in the PageTS for the records like this:
TCEFORM {
tx_news_domain_model_news {
categories.disabled = 1
}
}
Removed them from the administration filters and columns:
tx_news {
module {
columns = istopnews,datetime,author
filters {
categories = 0
categoryConjunction = 0
includeSubCategories = 0
}
}
}
Now I'd also like to disable them in the plugin settings when adding the plugin to the page. in the BackendUtility.php I found the following lines who will do that for me (notice I've added categories categoryConjunction,..):
public $removedFieldsInListView = [
'sDEF' => 'dateField,singleNews,previewHiddenRecords,selectedList,categories,categoryConjunction,includeSubCategories',
'additional' => '',
'template' => ''
];
Of course like this I've already disabled the categories, but by directly editing the extension instead of overriding it from my own extension, that means when I update tx_news I will lose that configuration.
What $GLOBALS[TCA].. stuff do I have to add to get the same result? I can't find anything in the backend debugging...
I'm searching something like (or some TypoScript stuff if possible):
$GLOBALS['TCA']['tx_news_domain_model_news']['plugin']['backendUtility'][removeFieldsInListView]= 'bla, blabla, bla';
I appreciate all the help!
Have you tried some TsConfig like that
TCEFORM {
tt_content {
pi_flexform {
news_pi1 {
sDEF {
# Important is the escaping of the dot which is part of the fieldname
settings\.orderBy.disabled = 1
}
}
}
}
}
Q : How can I show display different menu(s) by user role?
Description : the app has many roles. e.g HR manager, Account Manager, Operating Manager, Employee, Operator, ...., etc. I used rights and yii-user modules to create those roles. Those roles have different functions. So the app will show different menu for different user's role after logged in. Now, I can lock the function for different user. e.g when HR manger logged in, he/she can't route to other function of user role. But I don't know how to show the HR Menu for Hr Manager, only.
I am not a newbie for yii. but I'm a newbie for those modules (rihgts and yii-user).
If you're using RBAC you can set the 'visible' param of CMenu items depending on the users privileges, for example;
$this->widget('zii.widgets.CMenu',array(
'items'=>array(
array(
'label'=>'Home',
'url'=>array('site/index'),
),
array(
'label'=>'HR',
'url'=>array('/hr/index'),
'visible'=>Yii::app()->user->checkAccess('hr')
),
array(
'label'=>'Accounts',
'url'=>array('/account/index'),
'visible'=>Yii::app()->user->checkAccess('account')
),
array(
'label'=>'Operations',
'url'=>array('/operations/index'),
'visible'=>Yii::app()->user->checkAccess('operations')
),
),
);
This way users will only be able to see the items in the menu if they have access privileges for that area.
[EDIT]
As per simaremare's comment below, you can force caching of this query beyond the current request by extending CWebUser. Firstly, set your user to run through your new class (we'll call it TWebUser), so in your main.php config file;
'components'=>array(
'user'=>array(
...
'class'=>'TWebUser',
...
),
...
),
Now we need to create TWebUser to cache these beyond the current request (which is what CWebUser does (source code):
class TWebUser extends CWebUser
{
private $_access=array();
public function checkAccess($operation,$params=array(),$allowCaching=true)
{
if($allowCaching && $params===array() && isset($this->_access[$operation]))
return $this->_access[$operation];
$cache = Yii::app()->session['checkAccess'];
if($allowCaching && !$this->getIsGuest() && isset($cache[$operation]) && time() - $cache[$operation]['t'] < 1800)
{
$checkAccess = $cache[$operation]['p'];
} else {
$checkAccess = Yii::app()->getAuthManager()->checkAccess($operation,$this->getId(),$params);
if($allowCaching && !$this->getIsGuest())
{
$access = isset($cache) ? $cache : array();
$access[$operation] = array('p'=>$checkAccess, 't'=>time());
Yii::app()->session['checkAccess'] = $access;
}
}
return $this->_access[$operation] = $checkAccess;
}
}
Now your access results will be set for the whole session. This does mean that if you edit the RBAC permissions for a given account, they'll have to log out and log in again to see the new changes reflected in the browser.
I hope that helps! I'm sure I found this workaround from someone else (probably on SO), but I can't find the original post to give them credit.
You would wrap an if-statement around the menu-items that you may or may not want to show.
In the if-statement, you would have to test whether the user qualifies to see your menu-items.
For example:
<?php if (Yii::app()->user->isGuest): ?>
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array(
'label'=>'this menu item visible only for Guests (not logged in)',
'url'=>array('/site/index')),
),
)); ?>
<?php endif; ?>
In the magento system, I added the columns subscriber_firstname and subscriber_lastname to the newsletter_subscriber db table.
In the admin area of magento, I want the Newsletter>Newsletter Subscribers grid table to show:
customer first name if it exists, otherwise show newsletter_subscriber.subscriber_firstname if it exists, otherwise show nothing
customer last name if it exists, otherwise show newsletter_subscriber.subscriber_lastname if it exists, otherwise show nothing
Which magento files do I need to edit to make this work? How do I go about editing the files to make this work?
app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php
You'll want to condition this based off if subscriber_firstname or subscriber_lastname have values or not:
$this->addColumn('subscribername', array(
'header' => Mage::helper('newsletter')->__('Subscriber First Name'),
'index' => 'subscriber_firstname',
'default' => '----'
));
Also, make sure to make a copy of the core files and NOT edit them directly!
the quick and easy solution is to create a column render and select the correct field based on the subscriber type e.g.
app/code/local/Mage/Adminhtml/Block/Newsletter/Subscriber/Renderer/FirstName.php
class Mage_Adminhtml_Block_Newsletter_Subscriber_Renderer_FirstName extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render(Varien_Object $row) {
$value = '';
if ($row->getData('type') == 2) {
$value = $row->getData('customer_firstname');
}
else {
$value = $row->getData('subscriber_firstname');
}
return $value;
}
}
then add your render to a local copy of the subscriber grid class
app/code/local/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php
$this->addColumn('firstname', array(
'header' => Mage::helper('newsletter')->__('First Name'),
'index' => 'customer_firstname',
'default' => '----',
'renderer' => 'Mage_Adminhtml_Block_Newsletter_Subscriber_Renderer_FirstName'
));
Note. the search and sort will not work on the subscriber name fields, to get this working you will need to extend app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber/Collection.php