Disable deleting and editing posts

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Disable deleting and editing posts

Post by soylentgreen »

Hi

is there a way to forbid the editing and deleting of an user's own posts? The users should be allowed to create new ones, but it is neccessary that existing ones cannot be changed or removed.

I thought about removing the edit and delete links in the template, but there might be a more elegant solution.

any help would be appreciated
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Disable deleting and editing posts

Post by garvinhicking »

Hi!

You could do that by creating a custom PHP plugin, that checks if an item is being edited, and denies access. You can hook into the corresponding backend_display and other event hooks to check the item.

Serendipity itself does not restrict that, because in a blog environment its highly unusuall that an entry owner should not be able to edit his entries. :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

hi,

is there a howto how to create such plugins?

some example code would be extremley helpful
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

There is some documentation on www.s9y.org, and many things can be done by just looking at existing plugins.

The 'serendipity_event_entrycheck' plugin (available via spartacus) already goes into a similar direction, you can look that up for an example :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

thank you, i'll have a look
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

i have yet another question: how is it possible to cancel an event?

so i just have to hook into the update / delete event and cancel it...
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I don't think it's possible to cancel a hook once it's started.

I think you'll need to change the event_data instead.
Judebert
---
Website | Wishlist | PayPal
Fencer
Regular
Posts: 28
Joined: Fri Aug 11, 2006 9:26 am
Contact:

Post by Fencer »

soylentgreen wrote:thank you, i'll have a look
Please send me a note when you finish the plugin, I would use it as well, due to the same problem. 8)

Filip
http://BrainKing.com - play 80+ popular board games for free, 30,000+ registered users
http://BrainKing.info - the official blog of the BrainKing game site
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

judebert wrote:I don't think it's possible to cancel a hook once it's started.

I think you'll need to change the event_data instead.
the hook api tells the following
http://s9y.org/116.html wrote: backend_delete_entry - Called when deleting an entry. Input data: Entry data
would be setting the entry data's id to an invalid number an appropriate way to prevent the entry from being deleted? or should the entry data set to null?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

If you search the code for 'backend_delete_entry' you'll see that the hook gets executed with $id as $eventData before the DELETE SQL statements are set.

Thus, setting $id to "-1" or "0" would make all the DELETE statements not delete matching rows.

So, the answer is: Yes. :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

i have completed the plugin, if anyone is interested i can upload it or send it
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I'd love to see it!
Judebert
---
Website | Wishlist | PayPal
soylentgreen
Regular
Posts: 28
Joined: Sun Aug 20, 2006 2:54 pm

Post by soylentgreen »

here's the code

comments are welcome

please note that the plugin still allows to enter the editing / deleting screens, since i could not figure out a way to prevent that
Post Reply