Post by vijay.priyani » Sun Nov 11, 2012 5:44 pm

Hi, all i want to hide the Edit and delete button if user(other then admin) is logged in the admin section. user can add products but can not modify the products of other. admin can add or modify all products of other.

Attachments

Products_1352626801516.png

products page - Products_1352626801516.png (232.32 KiB) Viewed 426 times


Newbie

Posts

Joined
Mon Jul 23, 2012 6:57 pm

Post by pprmkr » Sun Nov 11, 2012 6:24 pm

Edit admin/controller/catalog/product.php

At line 11 add:

Code: Select all

$this->data['user_can_add'] = ($this->user->getUserName() == 'admin');
At line 350 change:

Code: Select all

			$action[] = array(
				'text' => $this->language->get('text_edit'),
				'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL')
			);
Into:

Code: Select all

			if( $this->data['user_can_add'] ) {
			$action[] = array(
				'text' => $this->language->get('text_edit'),
				'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL')
			);}
Edit admin/view/template/catalog/product_list.tpl
At line 17 change:

Code: Select all

<a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a>
Into:

Code: Select all

<?php if( $user_can_add ) {;?><a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a><?php }?>
Show the button Delete and link Edit only if username = admin

But if user is clever and edits the url and changes the route to route=catalog/product/update and adds product_id=1 he is able to edit product 1

To prevent that add some logic to function update()

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by vijay.priyani » Sun Nov 11, 2012 7:20 pm

Thanks,@pprmkr

Edit button is gone. But delete button is still there. when i am attempting to delete something. its shows a warning. snapshot attached.
I am also attaching the both files where the code is overwritten.

Once again thanks PPrmkr. You are amazing

Attachments

Products_1352631831155.png

whenclicking on deltet - Products_1352631831155.png (183.43 KiB) Viewed 421 times


Newbie

Posts

Joined
Mon Jul 23, 2012 6:57 pm

Post by pprmkr » Sun Nov 11, 2012 9:08 pm

Checked the files and works OK.

Little change: second delete button removed from tpl-file.

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands
Who is online

Users browsing this forum: No registered users and 43 guests