Hey all,
Just started working with G2, and have been looking into creating a module.
I want the module to add some permissions (everyone group - core.viewAll) to an image/album, by clicking a link (in the sidebar or under image). Is there a module like this that anyone knows of?
I currently am using useralbum (with edited default permissions) to set permissions so only the user who created/uploaded an album/image can see them.
However I need the option to allow certain images/albums to be viewed by everyone, chosen by the user, so it needs to be in a link.
I've been working with a few modules (tutorial module, jensperms, ItemPermissions.inc) but am not getting very far.
I'm having trouble getting the image/album id to be passed into the module, I just can't seem to get it.
Every time I run the module I get the following error:
Error (ERROR_PERMISSION_DENIED) : user id: 6 doesn't have permission: core.addDataItem for item id:
* in modules/core/classes/helpers/GalleryUserHelper_simple.class at line 47 (GalleryCoreApi::error)
* in modules/core/classes/GalleryCoreApi.class at line 477 (GalleryUserHelper_simple::assertHasItemPermission)
* in modules/publiclink/MyPage.inc at line 51 (GalleryCoreApi::assertHasItemPermission)
* in main.php at line 231 (MyPageController::handleRequest)
* in main.php at line 94
* in main.php at line 83
From what I can see it doesn't seem to be passing the itemId correctly.
I'm trying to access itemId with
GalleryUtilities::getRequestVariables('itemId');
I'm simply running the module by typing the url http://www.example.com/main.php?g2_view=publiclink.MyPage
I'm logged in as admin.
Unfortunately I can't give the URL for the gallery2 install, heres the sys info.
Gallery version 2.2.2
PHP version 5.2.1 apache2handler
Webserver Apache/2.2.3 (Ubuntu) DAV/2 SVN/1.4.3 PHP/5.2.1
Database mysqli 5.0.38-Ubuntu_0ubuntu1-log
Toolkits ImageMagick, Thumbnail, Gd
Operating system Linux <boxname> 2.6.20-16-generic #2 SMP Thu Jun 7 20:19:32 UTC 2007 i686
Browser Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)
I've searched for adays through the forum and can't find anything (easy enough for me to understand).
I can give more info if needed.
Any help would be greatly appreciated.
Posts: 32509
> I'm simply running the module by typing the url http://www.example.com/main.php?g2_view=publiclink.MyPage
you want the itemId to be part of the request but obviously there's no itemId parameter in that URL.
> However I need the option to allow certain images/albums to be viewed by everyone, chosen by the user, so it needs to be in a link.
so you don't want to give the owner the "change permission" permission, right? else they could change this on their own with the "edit permissions" link.
you'll want to use GalleryCoreApi::addGroupPermission(....) and GalleryCoreApi::removeGroupPermission(....)for this.
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 20
Thanks for the reply, I should've been more precise with my post.
When accessing the url I have tried http://www.example.com/main.php?g2_view=publiclink.MyPage?itemId=xxx, doesn't seem to get me any further, just loads the same page (modules/publiclink/templates/MyPage.tpl).
That's right, I don't want to give the users the ability to change any permissions, just to add/remove the specific permissions I want.
I'm trying to use
to set permissions, but I just can't seem to get in the itemId.
I have found this post (2nd post on page): http://gallery.menalto.com/node/63690
which seems to be useful, unfortunately I don't have the time to go through it now, but will work further on this tomorrow.
Again, thanks for the reply, must be frustrating dealing with all the questions on this board. :p
I'll update this thread with any more info (success or failure) that I come across.
Just for reference, heres my handleRequest function (in /modules/publiclink/MyPage.inc) (half destroyed from the tutorial module):
I know it's all over the place atm (and not following coding standards), just put it here for reference, will fix up when I get working.
Posts: 32509
> When accessing the url I have tried http://www.example.com/main.php?g2_view=publiclink.MyPage?itemId=xxx, doesn't seem to get me any further, just loads the same page (modules/publiclink/templates/MyPage.tpl).
should be g2_itemId= and not itemId=
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 20
Thanks for the response again, valiant.
I've now got things working quite well, just need to make it work from account without changePermission permission (best way to do this??).
Currently calling it with:
http://www.example.com/main.php?g2_view=core.ItemAdmin&g2_subView=publiclink.SetPerms&g2_itemId=xxx
This page simply shows a message displaying the current status (public/private), a button with "Make Public" or "Make Private", click the button it toggles whether the Everybody - core.viewAll is present or not (child items also inherit this).
Which seems to work fine.
I started again from the ground up and basically ended up with a simplified copy of ItemPermissions (view and controller).
Also need to create a block to display the link where I want it, but that shouldn't be that hard now that I'm getting an understanding of the structure of G2, I'll post back once I've done it.
Does all that sound right? :p
I'll also post the code soon, after it's been cleaned up.
Oh and Aosh, thanks for that post, helped quite a bit.
cOwMoO
Posts: 20
Well it's been a while since I was here (other work got the better of me) but I've started developing this module again, got it working quite nicely, although not exactly how I originally wanted it.
Basically I have 2 questions, the first being, is there any way I can perform actions in a block without ever going to a view? I want the user to be able to click a button/link in the block, and have it set certain permissions (in this case 'Everybody.viewAll'), and take the user straight back to the page they were viewing.
Right now they must click a link, which takes them to a view, from there they click a button which sets the permissions and takes them back to the original page they were viewing.
My other question is, can anyone see any improvements I can make to the following code, I'm sure there will be some, as I'm still not too familiar with the G2 framework and this is just a hacked up version of ItemPermissions.inc so I'm not 100% sure of what all the lines do.
Anyway, thanks in advance for any help, and also to the Dev team, fantastic product!