Skip to content

Instantly share code, notes, and snippets.

@javorszky
Created November 17, 2015 13:27
Show Gist options
  • Save javorszky/47994137d708d5d5c0bf to your computer and use it in GitHub Desktop.
Save javorszky/47994137d708d5d5c0bf to your computer and use it in GitHub Desktop.
<?php
array(
'/' => array('GP_Route_Index', 'index'),
/**
* No permission check
*/
'get:/profile' => array('GP_Route_Profile', 'profile_get'),
/**
* OKAY if user is logged in
* Otherwise redirects to wp_login_url with a redirect to the profile page
*/
"get:/profile/$path" => array('GP_Route_Profile', 'profile_view'),
/**
* No permission check
* Find a user with user_nicename == $path
* If not found, die_with_404
*/
'post:/profile' => array('GP_Route_Profile', 'profile_post'),
/**
* No permission check
* Checks for POST['submit']
* Saves per page and user_sort on current logged in user's meta
*/
'get:/languages' => array('GP_Route_Locale', 'locales_get'),
/**
* No permission check
* Gets the selected locales or all
*/
"get:/languages/$locale/$path" => array('GP_Route_Locale', 'single'),
/**
* No permission check
*/
"get:/languages/$locale" => array('GP_Route_Locale', 'single'),
/**
* No permission check
*/
"get:/$set/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_get'),
/**
* Checks current user.
* User should "approve", "translation-set" for this set id
* $can_edit = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* If can_edit is true, the glossary-view template will have extra markup / links
*/
"post:/$set/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_post'),
/**
* Checks current user
* User should "approve", "translation-set" for this set id
* $can_edit = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* If can_edit is false, it dies with a 403
*/
"post:/$set/glossary/-new" => array('GP_Route_Glossary_Entry', 'glossary_entry_add_post'),
/**
* Checks current user
* User should "approve", "translation-set" for this set id
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*
* Otherwise redirected to referer if exists or /projects
*/
"post:/$set/glossary/-delete" => array('GP_Route_Glossary_Entry', 'glossary_entry_delete_post'),
/**
* Checks current user
* $can_edit = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* If $can_edit is false, it dies with a 403
*/
"get:/$set/glossary/-export" => array('GP_Route_Glossary_Entry', 'export_glossary_entries_get'),
/**
* No permission check
*/
"get:/$set/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*
* Otherwise reidrects to referrer or /projects
*/
"post:/$set/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*
* Otherwise redirects to referrer or /projects
*/
"get:/$project/import-originals" => array('GP_Route_Project', 'import_originals_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* Otherwise redirects to referrer or /projects
*/
"post:/$project/import-originals" => array('GP_Route_Project', 'import_originals_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* Otherwise redirects to referrer or /projects
*/
"get:/$project/-edit" => array('GP_Route_Project', 'edit_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* Otherwise redirects to referrer or /projects
*/
"post:/$project/-edit" => array('GP_Route_Project', 'edit_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* Otherwise redirects to referrer or /projects
*/
/*
// Currently the deletion of a project is not well defined so don't add routes to let it happen.
"get:/$project/-delete" => array('GP_Route_Project', 'delete_get'),
"post:/$project/-delete" => array('GP_Route_Project', 'delete_post'),
*/
"post:/$project/-personal" => array('GP_Route_Project', 'personal_options_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"get:/$project/-permissions" => array('GP_Route_Project', 'permissions_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* (uses all validator permissions for this project id)
*/
"post:/$project/-permissions" => array('GP_Route_Project', 'permissions_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*
* Adds validator to translation-set
*/
"get:/$project/-permissions/-delete/$dir" => array('GP_Route_Project', 'permissions_delete'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"get:/$project/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"post:/$project/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"post:/$project/-mass-create-sets/preview" => array('GP_Route_Project', 'mass_create_sets_preview_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"get:/$project/-branch" => array('GP_Route_Project', 'branch_project_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->id )
*/
"post:/$project/-branch" => array('GP_Route_Project', 'branch_project_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $parent_project_id )
*/
"get:/$projects" => array('GP_Route_Project', 'index'),
/**
* No permission check
*/
"get:/$projects/-new" => array('GP_Route_Project', 'new_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $project->parent_project_id )
*/
"post:/$projects/-new" => array('GP_Route_Project', 'new_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $parent_project_id )
*/
"post:/$set/-bulk" => array('GP_Route_Translation', 'bulk_post'),
/**
* Checks current user
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*/
"get:/$set/import-translations" => array('GP_Route_Translation', 'import_translations_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*/
"post:/$set/import-translations" => array('GP_Route_Translation', 'import_translations_post'),
/**
* Check current user
* $this->cannot_and_redirect( 'approve', 'translation-set', $translation_set->id )
*/
"post:/$set/-discard-warning" => array('GP_Route_Translation', 'discard_warning'),
/**
* Uses edit_single_translation
* Check current user
* $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id );
* $can_write = $this->can( 'write', 'project', $project->id );
* $can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* Uses translation-row to display template
* Edit: (can) double-click to add translation / (can't but logged in) you are not allowed to edit / (not logged in) you need to log in to edit, and textareas enabled / disabled
* Write: Change priorities (?)
* Approve: checkbox in the th, textareas enabled / disabled
*/
"post:/$set/-set-status" => array('GP_Route_Translation', 'set_status'),
/**
* Uses edit_single_translation
* Checks current user
* $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id );
* $can_write = $this->can( 'write', 'project', $project->id );
* $can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* Same as discard warning
*/
"/$set/export-translations" => array('GP_Route_Translation', 'export_translations_get'),
/**
* No permission check
*/
// keep this below all URLs ending with a literal string, because it may catch one of them
"get:/$set" => array('GP_Route_Translation', 'translations_get'),
/**
* Checks current user
* $can_edit = $this->can( 'edit', 'translation-set', $translation_set->id );
* $can_write = $this->can( 'write', 'project', $project->id );
* $can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
*
* Approve: bulk actions editor toolbar, add link to create glossary, displays translation status, adds footer link to import translations
* Write: set priority (both individual and bulk)
*
* Uses translations template
* Includes translation-row
*/
"post:/$set" => array('GP_Route_Translation', 'translations_post'),
/**
* Checks current user
* $this->can_or_forbidden( 'edit', 'translation-set', $translation_set->id ); to short circuit (this needs to pass)
*
* Later
* $this->can( 'approve', 'translation-set', $translation_set->id ) or
* $this->can( 'write', 'project', $project->id )
* to set the status of data to either waiting, or currnet if any of the above match
*/
// keep this one at the bottom of the project, because it will catch anything starting with project
"/$project" => array('GP_Route_Project', 'single'),
/**
* Checks current user
* $can_write = $this->can( 'write', 'project', $project->id );
*
* Uses project template
* Adds project actions
*/
"get:/sets/-new" => array('GP_Route_Translation_Set', 'new_get'),
/**
* Checks current user
* $this->cannot_edit_set_and_redirect, which is just
* $this->cannot_and_redirect( 'write', 'project', $set->project_id );
*
* Uses translation-set-new template
*/
"post:/sets/-new" => array('GP_Route_Translation_Set', 'new_post'),
/**
* Checks current user
* $this->cannot_edit_set_and_redirect( $new_set )
*/
"get:/sets/$id" => array('GP_Route_Translation_Set', 'single'),
/**
* No permission check
*/
"get:/sets/$id/-edit" => array('GP_Route_Translation_Set', 'edit_get'),
/**
* Checks current user
* $this->cannot_and_redirect( 'write', 'project', $set->project_id, gp_url_project( $project ) )
*
* Redirects to the url of the project if can't write
*/
"post:/sets/$id/-edit" => array('GP_Route_Translation_Set', 'edit_post'),
/**
* Checks current user
* $this->cannot_edit_set_and_redirect( $new_set ) which is
* $this->cannot_and_redirect( 'write', 'project', $set->project_id );
*/
"get:/glossaries/-new" => array('GP_Route_Glossary', 'new_get'),
/**
* Checks current user
* $this->cannot_edit_glossary_and_redirect( $glossary )
* $this->cannot_and_redirect( 'approve', 'translation-set', $glossary->translation_set_id );
*/
"post:/glossaries/-new" => array('GP_Route_Glossary', 'new_post'),
/**
* Checks current user
* $this->cannot_edit_glossary_and_redirect( $new_glossary ) which is
* $this->cannot_and_redirect( 'approve', 'translation-set', $glossary->translation_set_id );
*/
"get:/glossaries/$id/-edit" => array('GP_Route_Glossary', 'edit_get'),
/**
* No permission check
*/
"post:/glossaries/$id/-edit" => array('GP_Route_Glossary', 'edit_post'),
/**
* $this->cannot_edit_glossary_and_redirect( $glossary ) which is
* $this->cannot_and_redirect( 'approve', 'translation-set', $glossary->translation_set_id );
*/
"post:/originals/$id/set_priority" => array('GP_Route_Original', 'set_priority'),
/**
* Checks current user
* $this->can_or_forbidden( 'write', 'project', $project->id );
*/
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment