Skip to content

Commit

Permalink
Small refactorings and code formatting for better readabilitiy
Browse files Browse the repository at this point in the history
  • Loading branch information
René Scheibe committed Aug 23, 2008
1 parent faea52d commit 28f4780
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 147 deletions.
37 changes: 26 additions & 11 deletions app/controllers/access_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
=begin
RailsCollab
-----------
Copyright (C) 2007 James S Urquhart (jamesu at gmail.com)This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Copyright (C) 2007 James S Urquhart (jamesu at gmail.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
=end

class AccessController < ApplicationController

layout 'dialog'

def index
if !@logged_user.nil?
redirect_to :controller => 'dashboard'
if @logged_user.nil?
redirect_to :action => 'login'
else
redirect_to :action => 'login'
redirect_to :controller => 'dashboard'
end
end

Expand All @@ -21,17 +36,17 @@ def login
when :post
login_params = params[:login]
remember = login_params[:remember]

# Normal boring username + password
@logged_user = User.authenticate(login_params['user'], login_params['password'])

if !@logged_user.nil?

if @logged_user.nil?
error_status(true, :login_failure)
else
error_status(false, :login_success)
redirect_back_or_default :controller => "dashboard"
redirect_back_or_default :controller => 'dashboard'

session['user_id'] = @logged_user.id
else
error_status(true, :login_failure)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class UserController < ApplicationController
def index
render :text => 'Hahaha!'
end

def add
if not User.can_be_created_by(@logged_user)
unless User.can_be_created_by(@logged_user)
error_status(true, :insufficient_permissions)
redirect_back_or_default :controller => 'dashboard'
return
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def avatar=(value)

content_type = value.content_type.chomp

if !['image/jpg', 'image/jpeg', 'image/gif', 'image/png'].include?(content_type)
unless ['image/jpg', 'image/jpeg', 'image/gif', 'image/png'].include?(content_type)
self.errors.add(:avatar, "Unsupported format")
return
end
Expand Down
1 change: 0 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
#config.action_view.cache_template_extensions = false
config.action_view.debug_rjs = true

# Don't care if the mailer can't send
Expand Down
136 changes: 65 additions & 71 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,114 +11,108 @@

# You can have the root of your site routed by hooking up ''
# -- just remember to delete public/index.html.
map.connect '', :controller => "dashboard"
map.connect '', :controller => 'dashboard'

# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named 'wsdl'
map.connect ':controller/service.wsdl', :action => 'wsdl'

# feed url's
map.connect 'feed/:user/:token/:action.:format', :controller => 'feed'
map.connect 'feed/:user/:token/:action.:format', :controller => 'feed'
map.connect 'feed/:user/:token/:action.:project.:format', :controller => 'feed'

# Account routes
map.connect 'account', :controller => 'account'
map.connect 'account', :controller => 'account'
map.connect 'account/avatar/:id.png', :controller => 'account', :action => 'avatar', :format => 'png'
['edit_profile', 'edit_password', 'update_permissions', 'edit_avatar', 'delete_avatar'].each do |action|
map.connect 'account/:action/:id', :controller => 'account', :action => action

%w[edit_profile edit_password update_permissions edit_avatar delete_avatar].each do |action|
map.connect 'account/:action/:id', :controller => 'account', :action => action
map.connect 'account/:action/:id.:format', :controller => 'account', :action => action
end

# Company routes
map.connect 'company/logo/:id.png', :controller => 'company', :action => 'logo', :format => 'png'
['card', 'view_client', 'edit', 'add_client', 'edit_client', 'delete_client', 'update_permissions',
'edit_logo', 'delete_logo', 'hide_welcome_info'].each do |action|
map.connect 'company/:action/:id', :controller => 'company', :action => action

%w[card view_client edit add_client edit_client delete_client
update_permissions edit_logo delete_logo hide_welcome_info].each do |action|
map.connect 'company/:action/:id', :controller => 'company', :action => action
map.connect 'company/:action/:id.:format', :controller => 'company', :action => action
end

# The rest of the simple controllers

['dashboard', 'access', 'administration', 'comment', 'user', 'config'].each do |controller|
map.connect "#{controller}/:action/:id", :controller => controller
%w[dashboard access administration comment user config].each do |controller|
map.connect "#{controller}/:action/:id", :controller => controller
map.connect "#{controller}/:action/:id.format", :controller => controller
end

map.connect "comment/add/:object_id.:object_type", :controller => 'comment', :action => 'add'

# BaseCamp API
map.connect 'project/list', :controller => 'basecamp', :action => 'projects_list'
map.connect 'project/show/:id', :controller => 'basecamp', :action => 'project_show'
map.connect 'projects/:active_project/attachment_categories', :controller => 'basecamp', :action => 'projects_attachment_categories'
map.connect 'projects/:active_project/post_categories', :controller => 'basecamp', :action => 'projects_post_categories'
map.connect 'contacts/companies', :controller => 'basecamp', :action => 'contacts_companies'
map.connect 'contacts/company/:id', :controller => 'basecamp', :action => 'contacts_company'
map.connect 'contacts/people/:id', :controller => 'basecamp', :action => 'contacts_people'
map.connect 'projects/:active_project/contacts/people/:id', :controller => 'basecamp', :action => 'contacts_people'
map.connect 'contacts/person/:id', :controller => 'basecamp', :action => 'contacts_person'

map.connect 'msg/comment/:id', :controller => 'basecamp', :action => 'msg_comment'
map.connect 'msg/comments/:id', :controller => 'basecamp', :action => 'msg_comments'
map.connect 'msg/create_comment/:id', :controller => 'basecamp', :action => 'msg_create_comment'
map.connect 'projects/:active_project/msg/create', :controller => 'basecamp', :action => 'projects_msg_create'
map.connect 'msg/delete_comment/:id', :controller => 'basecamp', :action => 'msg_delete_comment'
map.connect 'msg/delete/:id', :controller => 'basecamp', :action => 'msg_delete'
map.connect 'msg/get/:ids', :controller => 'basecamp', :action => 'msg_get',
:requirements => {:ids => %r([^/;?]+)}
map.connect 'projects/:active_project/msg/archive', :controller => 'basecamp', :action => 'projects_msg_archive'
map.connect 'projects/:active_project/msg/cat/:cat_id/archive', :controller => 'basecamp', :action => 'projects_msg_archive'
map.connect 'msg/update_comment', :controller => 'basecamp', :action => 'msg_update_comment'
map.connect 'msg/update/:id', :controller => 'basecamp', :action => 'msg_update'

map.connect 'todos/complete_item/:id', :controller => 'basecamp', :action => 'todos_complete_item'
map.connect 'todos/create_item/:list_id', :controller => 'basecamp', :action => 'todos_create_item'
map.connect 'projects/:active_project/todos/create_list', :controller => 'basecamp', :action => 'projects_todos_create_list'
map.connect 'todos/delete_item/:id', :controller => 'basecamp', :action => 'todos_delete_item'
map.connect 'todos/delete_list/:id', :controller => 'basecamp', :action => 'todos_delete_list'
map.connect 'todos/list/:id', :controller => 'basecamp', :action => 'todos_list'
map.connect 'projects/:active_project/todos/list/:id', :controller => 'basecamp', :action => 'todos_list'
map.connect 'projects/:active_project/todos/lists', :controller => 'basecamp', :action => 'projects_todos_lists'
map.connect 'todos/move_item/:id', :controller => 'basecamp', :action => 'todos_move_item'
map.connect 'todos/move_list/:id', :controller => 'basecamp', :action => 'todos_move_list'
map.connect 'todos/uncomplete_item/:id', :controller => 'basecamp', :action => 'todos_uncomplete_item'
map.connect 'todos/update_item/:id', :controller => 'basecamp', :action => 'todos_update_item'
map.connect 'todos/update_list/:id', :controller => 'basecamp', :action => 'todos_update_list'

map.connect 'milestones/complete/:id', :controller => 'basecamp', :action => 'milestones_complete'
map.connect 'projects/:active_project/milestones/create', :controller => 'basecamp', :action => 'projects_milestones_create'
map.connect 'milestones/delete/:id', :controller => 'basecamp', :action => 'milestones_delete'
map.connect 'projects/:active_project/milestones/list', :controller => 'basecamp', :action => 'projects_milestones_list'
map.connect 'milestones/uncomplete/:id', :controller => 'basecamp', :action => 'milestones_uncomplete'
map.connect 'milestones/update/:id', :controller => 'basecamp', :action => 'milestones_update'

map.connect 'time/save_entry', :controller => 'basecamp', :action => 'time_save_entry'
map.connect 'projects/:active_project/time/delete_entry/:id', :controller => 'basecamp', :action => 'projects_time_delete_entry'
map.connect 'time/report/:id/:from/:to/:filter', :controller => 'basecamp', :action => 'time_report'
map.connect 'time/report//:from/:to/:filter', :controller => 'basecamp', :action => 'time_report' # Dodgy widget hack
map.connect 'time/save_entry/:id', :controller => 'basecamp', :action => 'time_update_entry'
map.connect 'project/list', :controller => 'basecamp', :action => 'projects_list'
map.connect 'project/show/:id', :controller => 'basecamp', :action => 'project_show'
map.connect 'projects/:active_project/attachment_categories', :controller => 'basecamp', :action => 'projects_attachment_categories'
map.connect 'projects/:active_project/post_categories', :controller => 'basecamp', :action => 'projects_post_categories'
map.connect 'contacts/companies', :controller => 'basecamp', :action => 'contacts_companies'
map.connect 'contacts/company/:id', :controller => 'basecamp', :action => 'contacts_company'
map.connect 'contacts/people/:id', :controller => 'basecamp', :action => 'contacts_people'
map.connect 'projects/:active_project/contacts/people/:id', :controller => 'basecamp', :action => 'contacts_people'
map.connect 'contacts/person/:id', :controller => 'basecamp', :action => 'contacts_person'
map.connect 'msg/comment/:id', :controller => 'basecamp', :action => 'msg_comment'
map.connect 'msg/comments/:id', :controller => 'basecamp', :action => 'msg_comments'
map.connect 'msg/create_comment/:id', :controller => 'basecamp', :action => 'msg_create_comment'
map.connect 'projects/:active_project/msg/create', :controller => 'basecamp', :action => 'projects_msg_create'
map.connect 'msg/delete_comment/:id', :controller => 'basecamp', :action => 'msg_delete_comment'
map.connect 'msg/delete/:id', :controller => 'basecamp', :action => 'msg_delete'
map.connect 'msg/get/:ids', :controller => 'basecamp', :action => 'msg_get', :requirements => {:ids => %r([^/;?]+)}
map.connect 'projects/:active_project/msg/archive', :controller => 'basecamp', :action => 'projects_msg_archive'
map.connect 'projects/:active_project/msg/cat/:cat_id/archive', :controller => 'basecamp', :action => 'projects_msg_archive'
map.connect 'msg/update_comment', :controller => 'basecamp', :action => 'msg_update_comment'
map.connect 'msg/update/:id', :controller => 'basecamp', :action => 'msg_update'
map.connect 'todos/complete_item/:id', :controller => 'basecamp', :action => 'todos_complete_item'
map.connect 'todos/create_item/:list_id', :controller => 'basecamp', :action => 'todos_create_item'
map.connect 'projects/:active_project/todos/create_list', :controller => 'basecamp', :action => 'projects_todos_create_list'
map.connect 'todos/delete_item/:id', :controller => 'basecamp', :action => 'todos_delete_item'
map.connect 'todos/delete_list/:id', :controller => 'basecamp', :action => 'todos_delete_list'
map.connect 'todos/list/:id', :controller => 'basecamp', :action => 'todos_list'
map.connect 'projects/:active_project/todos/list/:id', :controller => 'basecamp', :action => 'todos_list'
map.connect 'projects/:active_project/todos/lists', :controller => 'basecamp', :action => 'projects_todos_lists'
map.connect 'todos/move_item/:id', :controller => 'basecamp', :action => 'todos_move_item'
map.connect 'todos/move_list/:id', :controller => 'basecamp', :action => 'todos_move_list'
map.connect 'todos/uncomplete_item/:id', :controller => 'basecamp', :action => 'todos_uncomplete_item'
map.connect 'todos/update_item/:id', :controller => 'basecamp', :action => 'todos_update_item'
map.connect 'todos/update_list/:id', :controller => 'basecamp', :action => 'todos_update_list'
map.connect 'milestones/complete/:id', :controller => 'basecamp', :action => 'milestones_complete'
map.connect 'projects/:active_project/milestones/create', :controller => 'basecamp', :action => 'projects_milestones_create'
map.connect 'milestones/delete/:id', :controller => 'basecamp', :action => 'milestones_delete'
map.connect 'projects/:active_project/milestones/list', :controller => 'basecamp', :action => 'projects_milestones_list'
map.connect 'milestones/uncomplete/:id', :controller => 'basecamp', :action => 'milestones_uncomplete'
map.connect 'milestones/update/:id', :controller => 'basecamp', :action => 'milestones_update'
map.connect 'time/save_entry', :controller => 'basecamp', :action => 'time_save_entry'
map.connect 'projects/:active_project/time/delete_entry/:id', :controller => 'basecamp', :action => 'projects_time_delete_entry'
map.connect 'time/report/:id/:from/:to/:filter', :controller => 'basecamp', :action => 'time_report'
map.connect 'time/report//:from/:to/:filter', :controller => 'basecamp', :action => 'time_report' # Dodgy widget hack
map.connect 'time/save_entry/:id', :controller => 'basecamp', :action => 'time_update_entry'

# Useful BaseCamp RSS Feeds
map.connect '/feed/recent_items_rss', :controller => 'basecamp', :action => 'recent_items_rss'
map.connect '/feed/recent_items_rss', :controller => 'basecamp', :action => 'recent_items_rss'
map.connect 'projects/:active_project/feed/recent_items_rss', :controller => 'basecamp', :action => 'recent_project_items_rss'

# project & project object url's
map.connect 'project/add', :controller => 'project', :action => 'add'

map.connect 'project/:active_project/tags', :controller => 'project', :action => 'tags'
map.connect 'project/:active_project/tags/:id', :controller => 'tag', :action => 'project'
map.connect 'project/:active_project/tags', :controller => 'project', :action => 'tags'
map.connect 'project/:active_project/tags/:id', :controller => 'tag', :action => 'project'

map.connect '/files/thumbnail/:id.jpg', :controller => 'files', :action => 'thumbnail', :format => 'jpg'

['search', 'people', 'permissions', 'remove_user', 'remove_company', 'edit', 'delete', 'complete', 'open'].each do |action|
%w[search people permissions remove_user remove_company edit delete complete open].each do |action|
map.connect "project/:active_project/#{action}/:id", :controller => 'project', :action => action
end
['message', 'task', 'comment', 'milestone', 'time', 'files', 'tags', 'form', 'people'].each do |controller|
map.connect "project/:active_project/#{controller}/:action/:id", :controller => controller

%w[message task comment milestone time files tags form people].each do |controller|
map.connect "project/:active_project/#{controller}/:action/:id", :controller => controller
map.connect "project/:active_project/#{controller}/:action/:id.:format", :controller => controller
map.connect "project/:active_project/#{controller}", :controller => controller
map.connect "project/:active_project/#{controller}", :controller => controller
end

map.connect 'project/:active_project/:id', :controller => 'project', :action => 'overview'
Expand Down
Loading

0 comments on commit 28f4780

Please sign in to comment.