Commit Graph

44 Commits

Author SHA1 Message Date
Bharat Mediratta
6a13a238bb Convert the "parents" variable from a result iterator to an array so
that the theme can call empty() on it.  Fixes #1318.
2010-08-29 11:45:27 -07:00
Bharat Mediratta
7607e1f932 Full pass over all the JSON encoding and JS dialog code. We now abide
by the following rules:

1) An initial dialog or panel load can take either HTML or JSON, but
   the mime type must accurately reflect its payload.

2) dialog form submits can handle a pure HTML response, but the mime
   type must also be correct.  This properly resolves the problem
   where the reauth code gets a JSON response first from the reauth
   code, and then an HTML response when you reauth and continue on to
   a given form -- try it out with Admin > Settings > Advanced.

3) All JSON replies must set the mime type correctly.  The json::reply
   convenience function does this for us.

4) By default, any HTML content sent back in the JSON response should be
   in the "html" field, no longer the "form" field.

The combination of these allows us to stop doing boilerplate code like
this in our controllers:

  // Print our view, JSON encoded
  json::reply(array("form" => (string) $view));

instead, controllers can just return HTML, eg:

  // Print our view
  print $view;

That's much more intuitive for developers.
2010-07-31 21:16:17 -07:00
Tim Almdal
91a2c04a24 More patches as part of #1225. Change the 'core' modules to use the json::reply
method to set the content type header and encode the response as a json object
2010-07-31 15:44:55 -07:00
Tim Almdal
dbf3199e46 Fix for ticket #1181. Use $.getJSON to retrieve the json contents of the dialog. Convert all the controllers
that create the data to go into a dialog to return the html as part of a json object.
2010-07-06 14:12:01 -07:00
Bharat Mediratta
c3c2b45280 Update the copyright to 2010. It's only 3 months into the year :-) 2010-03-03 10:15:34 -08:00
Andy Staudacher
8412aeb133 For consistency, use straight Kohana_404_Exception instead of the event system. 2010-02-14 07:15:57 -08:00
Andy Staudacher
d53f6d0e05 Fix for tickets 1009 and 603: Show a themed error page to guests / registered users (not to admins though). And show a login form to guests for 404 (incl. insufficient view permissions) errors. 2010-02-12 16:40:44 -08:00
Andy Staudacher
6353a7c2de Security: Fix leaking of album / photo names. Reject previous fix for ticket 1009.
Side effect: Renaming auth::required_login() to login_page().
2010-02-11 14:28:32 -08:00
Tim Almdal
8ef08d2088 Refactor the code to display the login page if the user does not have view
permission into the common auth::require_login() method.
2010-02-10 08:53:39 -08:00
Tim Almdal
17f0a1b10f If the user does not have permission to view the album, photo or movie, redirect
to a logon page to allow the user to login.  Pass the target url as a session
variable to allow the user to be redirected where they want to go if the login
was successful.  Fixes ticket #1009.
2010-02-10 08:45:14 -08:00
Bharat Mediratta
e02675b730 Change "filename" to "name" in the edit album form. I'd rather have
consistency between field names than deal with underlying issues with
Forge bitching about the "name" property.
2010-01-19 19:31:01 -08:00
Bharat Mediratta
5a8449f16d Convert Photos_Controller::update() to use model based validation. 2010-01-16 11:12:27 -08:00
Bharat Mediratta
20bd09ff00 A more thorough fix for #745 and #940. Stop using the referer to
guess how to send the user back.  Instead, proxy the originating item
id through the edit forms so that we can tell exactly what page we
were on when we began editing.  If we were viewing the item, then
redirect to its new url (in case it changed) to fix ticket #745.  But
if we were viewing some other item, then just stay on the current page
to fix #940.

The page_type approach didn't work because you'd have the same
"collection" page_type when doing a context menu edit for an album.
2009-12-31 17:21:19 -08:00
Bharat Mediratta
f431d7e12e Convert a database call. 2009-12-16 18:04:44 -08:00
Bharat Mediratta
c803cb2909 Merge branch 'master' of git@github.com:gallery/gallery3 into bharat_dev 2009-12-01 19:44:29 -08:00
Bharat Mediratta
852653ef24 Clean up item routing a bit.
1) The new default route is "albums", and Albums_Controller::index() does the right thing
2) Items_Controller redirects to the appropriate specific controller
3) All item controllers now have show() instead of _show(), so that
   the routing code in url::parse_url() can get to it.  But that code is protected against
   receiving bogus requests.
2009-11-30 13:57:50 -08:00
Bharat Mediratta
dee3ee81e2 Database::orwhere() is now Database_Builder::or_where() 2009-11-26 20:25:32 -08:00
Bharat Mediratta
54be15191b Overload Database_Builder to add merge_where() which takes predefined
where clauses and adds them to the existing query.  Update all
existing queries that take an additional where clause to use it.
2009-11-26 18:47:40 -08:00
Bharat Mediratta
1fd0e14359 Convert all DB where() calls to take 3 arguments.
Convert all open_paren() calls to and_open() or or_open() as appropriate.
2009-11-26 12:09:04 -08:00
Tim Almdal
2d5c232c42 Refactor the album, movie and photo handling to remove the REST_Controller. Partial fix for ticket #917 2009-11-25 12:46:04 -08:00
Bharat Mediratta
1067e68292 Redesign the way that we consider page types to create buckets of page
types, and a subtype for specifics.  Currently the top level bucket

   collection, item, other

Here are the core subtypes so far:

   collection: album, search, tag
   item: movie, photo
   other: login, reset, comment-fragment, comment

It's legal to create new page_subtypes whenever you want.  Use the
appropriate page_type to get the coarse grain behavior that you want.
2009-11-17 14:04:45 -08:00
Tim Almdal
88852c45ea Modified the so that a where clause can be passed into item::get_position. Was also able to remove the sub-select from the calculation of the current position as we already have the child item containing the sort column value.
Also added a where clause that ignores albums to the get_position, children and children_count method calls in photos.php and movies.php
2009-11-04 09:50:49 -08:00
Tim Almdal
4cb9ec1d6d Use the request::referrer to determine if we are editting the photo or album
from the context menu or from its photo or album page.
Fixes ticket #745.  Thanks to jankoprowski for the referrer approach.
2009-10-22 13:11:02 -07:00
Tim Almdal
95f3eb3aad When an album or photo is updated always return the photo/album location as
part of the response.  This insures that if the internet address changes, then
the page will reload properly.
2009-10-22 07:37:14 -07:00
Bharat Mediratta
0a66ef9cc7 Don't allow users to change the file extension of photos/movies
If you can change the extension, then you can alter the way the server
handles the file, which is a security problem.  So for example, you
can change a .JPG to a .PHP and then if you put some malicious PHP
code in the EXIF data, you can get the server to execute
it. Vulnerability is low because only users who have edit permissions
could do this.

Fixes ticket #846
2009-10-13 10:36:50 -07:00
Bharat Mediratta
123afc9542 Set children_count to 0, photos have no children. 2009-09-21 21:22:07 -07:00
Bharat Mediratta
9e6be40e31 Add viewable() protection to children() and children_count() calls.
This is not currently necessary (nor is it a security hole) because we
don't constrain permissions at the child level in the core, but it
makes our security audits easier and will enable the scenario where
somebody writes a module to add per-photo permissions.
2009-09-21 20:47:55 -07:00
Bharat Mediratta
a6581ede0b Fix Item_Model::get_position() so that our sort is stable when the comparison
row has a null value in the sort field.  Fix for #627

Note: this changes get_position() to take an Item_Model instead of an id!
2009-09-21 11:35:27 -07:00
Bharat Mediratta
2aad580f53 Move specialized (pretty) url generation back into Item_Model so that
we're not relying on overriding url::site() to do tricks around item
urls.  This means that you won't get item urls by doing
url::site("albums/37"), for example, but it also means that we won't
get pretty urls where we don't expect them (like in the action of a
<form> element).

Incidentally, this will help us move over to using the slug format
because if you've got a bad character in a url, the edit forms will
now work on it since they'll be id based.
2009-09-08 13:44:52 -07:00
Bharat Mediratta
78a42d9b83 1. Actually set the slug to the new value in the controllers.
2. Fix up an issue where we were crashing if there were no conflicting rows
3. Amend Item_Model so that if you change the slug, it flushes the cache
   for all children
2009-09-07 21:09:52 -07:00
Bharat Mediratta
f28353f4e1 Add the 'Internet Address' field to all items, along with proper
validation for the fields.
2009-09-07 21:01:51 -07:00
Bharat Mediratta
c887170555 Stay on the same page when editing albums/movies/photos. Fixes ticket 2009-08-31 21:10:22 -07:00
Andy Staudacher
8312eb116e XSS review fixes (mostly adding missing html::mark_clean()) calls. 2009-08-31 02:12:01 -07:00
Andy Staudacher
c01ac42c46 Refactor all calls of p::clean() to SafeString::of() and p::purify() to SafeString::purify().
Removing any p::clean() calls for arguments to t() and t2() since their args are wrapped in a SafeString anyway.
2009-08-29 12:48:40 -07:00
Tim Almdal
a7f4d7aced Revert commit 078c77a62b and change the
tag_event:item_edit_form to use the new Form_Script library to inject
script into a form.

Signed-off-by: Tim Almdal <tnalmdal@shaw.ca>
2009-07-28 21:00:25 +08:00
Tim Almdal
078c77a62b Add tag autocomplete to the album and photo edit pop up dialogs.
This required putting a wrapper view around the forms and passing
this view as the parameter to the item_edit_form event.  The view
contains a $script variable that the modules can add script to be
included in the form html when rendered as part of the ajax response.
2009-07-24 14:18:15 -07:00
Bharat Mediratta
60d6058880 Make some API changes simplify the tag editing code. We now have a
good pattern for allowing modules to add their own hooks to item forms!

1) Album, photo and movie forms now all use edit_item as the group and
   we publish item_edit_form and item_edit_form_completed events which
   makes it much easier in the module to handle all events.  They can
   still differentiate based on $item->type if they want to.

2) Added tag::clear_all() and tag::compact() functions which takes the
   place of hiwilson's tag::update() function and is now used in
   tag_event::item_delete().  This provides a simple API that allows
   us to have a lot less event handling code.  It's less efficient
   than what hiwilson was doing before in that it will delete and
   re-add tags, but if that ever turns out to be a performance issue
   we can do something about it then.
2009-07-20 08:51:12 -07:00
hiwilson
709d6c5faf (1)Add tag edit field in album/photo edit form. (2)provide edit functionality. (3)support multi-word tagging. 2009-07-20 08:02:07 -07:00
Bharat Mediratta
0f766b149d Second non-trivial change to the event code. We now publish model
related events from within the model handling code.  The only
exception to this currently is item_created which is challenging
because we have to save the item using ORM_MPTT::add_to_parent()
before the object itself is fully set up.  When we get that down to
one call to save() we can publish that event from within the model
also.
2009-07-16 12:31:40 -07:00
Bharat Mediratta
5b3b675b6d Non-trivial changes to the event handling code:
1) The item_updated event no longer takes the old and new items.
   Instead we overload ORM to track the original data and make
   that available via the item.  This will allow us to move event
   publishing down into the API methods which in turn will give us
   more stability since we won't require each controller to remember
   to do it.

2) ORM class now tracks the original values.  It doesn't track
   the original relationships (no need for that, yet)

3) Added new events:
     item_deleted
     group_deleted
     user_deleted
2009-07-16 11:19:34 -07:00
Bharat Mediratta
8f9a943f55 Fix a bunch of XSS vulnerabilities turned up by manual inspection
using the checklist in ticket #385.
2009-07-01 17:57:39 -07:00
Bharat Mediratta
4f0a3fefa0 Fix a bug in Item_Model::get_position() where we incorrectly using the
grandparent id.  Oops.  This caused navigation from photo back up to
album to be broken.

Also update Photos_Controller to use the active sort order.. it was
still hardcoded to use the id.  It's more efficient now, yay.

Fixes ticket #340.
2009-06-04 22:11:08 -07:00
Bharat Mediratta
43abcd9386 Security pass over all controller code. Mostly adding CSRF checking
and verifying user permissions, but there are several above-the-bar
changes:

1) Server add is now only available to admins.  This is a hard
   requirement because we have to limit server access (eg:
   server_add::children) to a user subset and the current permission
   model doesn't include that.  Easiest fix is to restrict to admins.
   Got rid of the server_add permission.

2) We now know check permissions at every level, which means in
   controllers AND in helpers.  This "belt and suspenders" approach will
   give us defense in depth in case we overlook it in one area.

3) We now do CSRF checking in every controller method that changes the
   code, in addition to the Forge auto-check.  Again, defense in depth
   and it makes scanning the code for security much simpler.

4) Moved Simple_Uploader_Controller::convert_filename_to_title to
   item:convert_filename_to_title

5) Fixed a bug in sending notification emails.

6) Fixed the Organize code to verify that you only have access to your
   own tasks.  In general, added permission checks to organize which had
   pretty much no validation code.

I did my best to verify every feature that I touched.
2009-06-01 22:40:22 -07:00
Bharat Mediratta
28b41056e3 Restructure things so that the application is now just another module.
Kohana makes this type of transition fairly straightforward in that
all controllers/helpers/etc are still located in the cascading
filesystem without any extra effort, except that I've temporarily
added a hack to force modules/gallery into the module path.

Rename what's left of "core" to be "application" so that it conforms
more closely to the Kohana standard (basically, just
application/config/config.php which is the minimal thing that you need
in the application directory)

There's still considerable work left to be done here.
2009-05-27 15:07:27 -07:00