From 990347307686fde0adfa3003c828c7655a90229f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 12 Apr 2012 13:27:01 +0200 Subject: [PATCH] Code cleanup, we only use json as backend. --- app/controllers/groups_controller.rb | 60 ++------- app/controllers/organizations_controller.rb | 60 ++------- app/controllers/roles_controller.rb | 55 ++------ app/controllers/settings_controller.rb | 52 ++------ app/controllers/ticket_articles_controller.rb | 49 +++---- .../ticket_priorities_controller.rb | 37 ++--- app/controllers/ticket_states_controller.rb | 37 ++--- app/controllers/tickets_controller.rb | 37 ++--- app/controllers/users_controller.rb | 126 ++++++------------ 9 files changed, 139 insertions(+), 374 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 60d12764a..8c003cdd8 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -2,85 +2,47 @@ class GroupsController < ApplicationController before_filter :authentication_check # GET /groups - # GET /groups.json def index @groups = Group.all - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @groups } - end + render :json => @groups end # GET /groups/1 - # GET /groups/1.json def show @group = Group.find(params[:id]) - respond_to do |format| - format.html # show.html.erb - format.json { render :json => @group } - end - end - - # GET /groups/new - # GET /groups/new.json - def new - @group = Group.new - - respond_to do |format| - format.html # new.html.erb - format.json { render :json => @group } - end - end - - # GET /groups/1/edit - def edit - @group = Group.find(params[:id]) + render :json => @group end # POST /groups - # POST /groups.json def create @group = Group.new(params[:group]) @group.created_by_id = current_user.id - respond_to do |format| - if @group.save - format.html { redirect_to @group, :notice => 'Group was successfully created.' } - format.json { render :json => @group, :status => :created } - else - format.html { render :action => "new" } - format.json { render :json => @group.errors, :status => :unprocessable_entity } - end + if @group.save + render :json => @group, :status => :created + else + render :json => @group.errors, :status => :unprocessable_entity end end # PUT /groups/1 - # PUT /groups/1.json def update @group = Group.find(params[:id]) - respond_to do |format| - if @group.update_attributes(params[:group]) - format.html { redirect_to @group, :notice => 'Group was successfully updated.' } - format.json { render :json => @group, :status => :ok } - else - format.html { render :action => "edit" } - format.json { render :json => @group.errors, :status => :unprocessable_entity } - end + if @group.update_attributes(params[:group]) + render :json => @group, :status => :ok + else + render :json => @group.errors, :status => :unprocessable_entity end end # DELETE /groups/1 - # DELETE /groups/1.json def destroy @group = Group.find(params[:id]) @group.destroy - respond_to do |format| - format.html { redirect_to groups_url } - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 9b7e77cd4..388eb5427 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -2,85 +2,47 @@ class OrganizationsController < ApplicationController before_filter :authentication_check # GET /organizations - # GET /organizations.json def index @organizations = Organization.all - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @organizations } - end + render :json => @organizations end # GET /organizations/1 - # GET /organizations/1.json def show @organization = Organization.find(params[:id]) - respond_to do |format| - format.html # show.html.erb - format.json { render :json => @organization } - end - end - - # GET /organizations/new - # GET /organizations/new.json - def new - @organization = Organization.new - - respond_to do |format| - format.html # new.html.erb - format.json { render :json => @organization } - end - end - - # GET /organizations/1/edit - def edit - @organization = Organization.find(params[:id]) + render :json => @organization end # POST /organizations - # POST /organizations.json def create @organization = Organization.new(params[:organization]) @organization.created_by_id = current_user.id - respond_to do |format| - if @organization.save - format.html { redirect_to @organization, :notice => 'Organization was successfully created.' } - format.json { render :json => @organization, :status => :created } - else - format.html { render :action => "new" } - format.json { render :json => @organization.errors, :status => :unprocessable_entity } - end + if @organization.save + render :json => @organization, :status => :created + else + render :json => @organization.errors, :status => :unprocessable_entity end end # PUT /organizations/1 - # PUT /organizations/1.json def update @organization = Organization.find(params[:id]) - respond_to do |format| - if @organization.update_attributes(params[:organization]) - format.html { redirect_to @organization, :notice => 'Organization was successfully updated.' } - format.json { render :json => @organization, :status => :ok } - else - format.html { render :action => "edit" } - format.json { render :json => @organization.errors, :status => :unprocessable_entity } - end + if @organization.update_attributes(params[:organization]) + render :json => @organization, :status => :ok + else + render :json => @organization.errors, :status => :unprocessable_entity end end # DELETE /organizations/1 - # DELETE /organizations/1.json def destroy @organization = Organization.find(params[:id]) @organization.destroy - respond_to do |format| - format.html { redirect_to organizations_url } - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 0cc703238..0dbe7c560 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -2,85 +2,54 @@ class RolesController < ApplicationController before_filter :authentication_check # GET /roles - # GET /roles.json def index @roles = Role.all - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @roles } - end + render :json => @roles end # GET /roles/1 - # GET /roles/1.json def show @role = Role.find(params[:id]) - respond_to do |format| - format.html # show.html.erb - format.json { render :json => @role } - end + render :json => @role end # GET /roles/new - # GET /roles/new.json def new @role = Role.new - respond_to do |format| - format.html # new.html.erb - format.json { render :json => @role } - end - end - - # GET /roles/1/edit - def edit - @role = Role.find(params[:id]) + render :json => @role end # POST /roles - # POST /roles.json def create @role = Role.new(params[:role]) @role.created_by_id = current_user.id - respond_to do |format| - if @role.save - format.html { redirect_to @role, :notice => 'Role was successfully created.' } - format.json { render :json => @role, :status => :created } - else - format.html { render :action => "new" } - format.json { render :json => @role.errors, :status => :unprocessable_entity } - end + if @role.save + render :json => @role, :status => :created + else + render :json => @role.errors, :status => :unprocessable_entity end end # PUT /roles/1 - # PUT /roles/1.json def update @role = Role.find(params[:id]) - respond_to do |format| - if @role.update_attributes(params[:role]) - format.html { redirect_to @role, :notice => 'Role was successfully updated.' } - format.json { render :json => @role, :status => :ok } - else - format.html { render :action => "edit" } - format.json { render :json => @role.errors, :status => :unprocessable_entity } - end + if @role.update_attributes(params[:role]) + render :json => @role, :status => :ok + else + render :json => @role.errors, :status => :unprocessable_entity end end # DELETE /roles/1 - # DELETE /roles/1.json def destroy @role = Role.find(params[:id]) @role.destroy - respond_to do |format| - format.html { redirect_to roles_url } - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 1554d0816..206d85c5f 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -2,76 +2,46 @@ class SettingsController < ApplicationController before_filter :authentication_check # GET /settings - # GET /settings.json def index @settings = Setting.all - respond_to do |format| - format.json { render :json => @settings } - end + render :json => @settings end # GET /settings/1 - # GET /settings/1.json def show @setting = Setting.find(params[:id]) - respond_to do |format| - format.json { render :json => @setting } - end - end - - # GET /settings/new - # GET /settings/new.json - def new - @setting = Setting.new - - respond_to do |format| - format.json { render :json => @setting } - end - end - - # GET /settings/1/edit - def edit - @setting = Setting.find(params[:id]) + render :json => @setting end # POST /settings - # POST /settings.json def create @setting = Setting.new(params[:setting]) - respond_to do |format| - if @setting.save - format.json { render :json => @setting, :status => :created } - else - format.json { render :json => @setting.errors, :status => :unprocessable_entity } - end + if @setting.save + render :json => @setting, :status => :created + else + render :json => @setting.errors, :status => :unprocessable_entity end end # PUT /settings/1 - # PUT /settings/1.json def update @setting = Setting.find(params[:id]) - respond_to do |format| - if @setting.update_attributes(params[:setting]) - format.json { render :json => @setting, :status => :ok } - else - format.json { render :json => @setting.errors, :status => :unprocessable_entity } - end + if @setting.update_attributes(params[:setting]) + render :json => @setting, :status => :ok + else + render :json => @setting.errors, :status => :unprocessable_entity end end # DELETE /settings/1 - # DELETE /settings/1.json def destroy @setting = Setting.find(params[:id]) @setting.destroy - respond_to do |format| - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index 16e7f4a51..d6f911c6c 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -2,27 +2,20 @@ class TicketArticlesController < ApplicationController before_filter :authentication_check # GET /articles - # GET /articles.json def index @articles = Ticket::Article.all - respond_to do |format| - format.json { render :json => @articles } - end + render :json => @articles end # GET /articles/1 - # GET /articles/1.json def show @article = Ticket::Article.find(params[:id]) - respond_to do |format| - format.json { render :json => @article } - end + render :json => @article end # POST /articles - # POST /articles.json def create @article = Ticket::Article.new(params[:ticket_article]) @article.created_by_id = current_user.id @@ -33,43 +26,35 @@ class TicketArticlesController < ApplicationController :o_id => @article.ticket_id ) - respond_to do |format| - if @article.save - format.json { render :json => @article, :status => :created } - - # remove attachments from upload cache - Store.remove( - :object => 'UploadCache::TicketZoom::' + current_user.id.to_s, - :o_id => @article.ticket_id - ) - else - format.json { render :json => @article.errors, :status => :unprocessable_entity } - end + if @article.save + render :json => @article, :status => :created + + # remove attachments from upload cache + Store.remove( + :object => 'UploadCache::TicketZoom::' + current_user.id.to_s, + :o_id => @article.ticket_id + ) + else + render :json => @article.errors, :status => :unprocessable_entity end end # PUT /articles/1 - # PUT /articles/1.json def update @article = Ticket::Article.find(params[:id]) - respond_to do |format| - if @article.update_attributes(params[:ticket_article]) - format.json { render :json => @article, :status => :ok } - else - format.json { render :json => @article.errors, :status => :unprocessable_entity } - end + if @article.update_attributes(params[:ticket_article]) + render :json => @article, :status => :ok + else + render :json => @article.errors, :status => :unprocessable_entity end end # DELETE /articles/1 - # DELETE /articles/1.json def destroy @article = Ticket::Article.find(params[:id]) @article.destroy - respond_to do |format| - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/ticket_priorities_controller.rb b/app/controllers/ticket_priorities_controller.rb index c266ea650..b3154f561 100644 --- a/app/controllers/ticket_priorities_controller.rb +++ b/app/controllers/ticket_priorities_controller.rb @@ -2,61 +2,46 @@ class TicketPrioritiesController < ApplicationController before_filter :authentication_check # GET /ticket_priorities - # GET /ticket_priorities.json def index @ticket_priorities = Ticket::Priority.all - respond_to do |format| - format.json { render :json => @ticket_priorities } - end + render :json => @ticket_priorities end # GET /ticket_priorities/1 - # GET /ticket_priorities/1.json def show @ticket_priority = Ticket::Priority.find(params[:id]) - respond_to do |format| - format.json { render :json => @ticket_priority } - end + render :json => @ticket_priority end # POST /ticket_priorities - # POST /ticket_priorities.json def create @ticket_priority = Ticket::Priority.new(params[:ticket_priority]) - respond_to do |format| - if @ticket_priority.save - format.json { render :json => @ticket_priority, :status => :created } - else - format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity } - end + if @ticket_priority.save + render :json => @ticket_priority, :status => :created + else + render :json => @ticket_priority.errors, :status => :unprocessable_entity end end # PUT /ticket_priorities/1 - # PUT /ticket_priorities/1.json def update @ticket_priority = Ticket::Priority.find(params[:id]) - respond_to do |format| - if @ticket_priority.update_attributes(params[:ticket_priority]) - format.json { render :json => @ticket_priority, :status => :ok } - else - format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity } - end + if @ticket_priority.update_attributes(params[:ticket_priority]) + render :json => @ticket_priority, :status => :ok + else + render :json => @ticket_priority.errors, :status => :unprocessable_entity end end # DELETE /ticket_priorities/1 - # DELETE /ticket_priorities/1.json def destroy @ticket_priority = Ticket::Priority.find(params[:id]) @ticket_priority.destroy - respond_to do |format| - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/ticket_states_controller.rb b/app/controllers/ticket_states_controller.rb index 9bf7a01e4..49797cb60 100644 --- a/app/controllers/ticket_states_controller.rb +++ b/app/controllers/ticket_states_controller.rb @@ -2,61 +2,46 @@ class TicketStatesController < ApplicationController before_filter :authentication_check # GET /ticket_states - # GET /ticket_states.json def index @ticket_states = Ticket::State.all - respond_to do |format| - format.json { render :json => @ticket_states } - end + render :json => @ticket_states end # GET /ticket_states/1 - # GET /ticket_states/1.json def show @ticket_state = Ticket::State.find(params[:id]) - respond_to do |format| - format.json { render :json => @ticket_state } - end + render :json => @ticket_state end # POST /ticket_states - # POST /ticket_states.json def create @ticket_state = Ticket::State.new(params[:ticket_state]) - respond_to do |format| - if @ticket_state.save - format.json { render :json => @ticket_state, :status => :created } - else - format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity } - end + if @ticket_state.save + render :json => @ticket_state, :status => :created + else + render :json => @ticket_state.errors, :status => :unprocessable_entity end end # PUT /ticket_states/1 - # PUT /ticket_states/1.json def update @ticket_state = Ticket::State.find(params[:id]) - respond_to do |format| - if @ticket_state.update_attributes(params[:ticket_state]) - format.json { render :json => @ticket_state, :status => :ok } - else - format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity } - end + if @ticket_state.update_attributes(params[:ticket_state]) + render :json => @ticket_state, :status => :ok + else + render :json => @ticket_state.errors, :status => :unprocessable_entity end end # DELETE /ticket_states/1 - # DELETE /ticket_states/1.json def destroy @ticket_state = Ticket::State.find(params[:id]) @ticket_state.destroy - respond_to do |format| - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 52a523bb2..3c51d8243 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -2,62 +2,47 @@ class TicketsController < ApplicationController before_filter :authentication_check # GET /tickets - # GET /tickets.json def index @tickets = Ticket.all - respond_to do |format| - format.json { render :json => @tickets } - end + render :json => @tickets end # GET /tickets/1 - # GET /tickets/1.json def show @ticket = Ticket.find(params[:id]) - respond_to do |format| - format.json { render :json => @ticket } - end + render :json => @ticket end # POST /tickets - # POST /tickets.json def create @ticket = Ticket.new(params[:ticket]) @ticket.created_by_id = current_user.id - respond_to do |format| - if @ticket.save - format.json { render :json => @ticket, :status => :created } - else - format.json { render :json => @ticket.errors, :status => :unprocessable_entity } - end + if @ticket.save + render :json => @ticket, :status => :created + else + render :json => @ticket.errors, :status => :unprocessable_entity end end # PUT /tickets/1 - # PUT /tickets/1.json def update @ticket = Ticket.find(params[:id]) - respond_to do |format| - if @ticket.update_attributes(params[:ticket]) - format.json { render :json => @ticket, :status => :ok } - else - format.json { render :json => @ticket.errors, :status => :unprocessable_entity } - end + if @ticket.update_attributes(params[:ticket]) + render :json => @ticket, :status => :ok + else + render :json => @ticket.errors, :status => :unprocessable_entity end end # DELETE /tickets/1 - # DELETE /tickets/1.json def destroy @ticket = Ticket.find(params[:id]) @ticket.destroy - respond_to do |format| - format.json { head :ok } - end + head :ok end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 006860483..56fa68956 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,7 +2,6 @@ class UsersController < ApplicationController before_filter :authentication_check, :except => [:create] # GET /users - # GET /users.json def index @users = User.all @@ -17,118 +16,81 @@ class UsersController < ApplicationController i[:organization_id] = organization_id } - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @users } - end + render :json => @users end # GET /users/1 - # GET /users/1.json def show # @user = User.find(params[:id]) @user = user_data_full(params[:id]) - respond_to do |format| - format.html # show.html.erb - format.json { render :json => @user } - end - end - - # GET /users/new - # GET /users/new.json - def new - @user = User.new - - respond_to do |format| - format.html # new.html.erb - format.json { render :json => @user } - end - end - - # GET /users/1/edit - def edit - @user = User.find(params[:id]) + render :json => @user end # POST /users - # POST /users.json def create @user = User.new(params[:user]) @user.created_by_id = (current_user && current_user.id) || 1 - respond_to do |format| - if @user.save + if @user.save - # if it's a signup, add user to customer role - if @user.created_by_id == 1 - - # check if it's first user - count = User.all.count() - role_ids = [] - if count <= 2 - role_ids.push Role.where( :name => 'Admin' ).first.id - role_ids.push Role.where( :name => 'Agent' ).first.id - else - role_ids.push Role.where( :name => 'Customer' ).first.id - end - @user.role_ids = role_ids - - # else do assignment as defined - else - if params[:role_ids] - @user.role_ids = params[:role_ids] - end - if params[:group_ids] - @user.group_ids = params[:group_ids] - end - end + # if it's a signup, add user to customer role + if @user.created_by_id == 1 - # send inviteation if needed - if params[:invite] - -# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII') -# exit '123' + # check if it's first user + count = User.all.count() + role_ids = [] + if count <= 2 + role_ids.push Role.where( :name => 'Admin' ).first.id + role_ids.push Role.where( :name => 'Agent' ).first.id + else + role_ids.push Role.where( :name => 'Customer' ).first.id end - format.html { redirect_to @user, :notice => 'User was successfully created.' } - format.json { render :json => @user, :status => :created } + @user.role_ids = role_ids + + # else do assignment as defined else - format.html { render :action => "new" } - format.json { render :json => @user.errors, :status => :unprocessable_entity } - end - end - end - - # PUT /users/1 - # PUT /users/1.json - def update - @user = User.find(params[:id]) - - respond_to do |format| - if @user.update_attributes(params[:user]) if params[:role_ids] @user.role_ids = params[:role_ids] end if params[:group_ids] @user.group_ids = params[:group_ids] end - format.html { redirect_to @user, :notice => 'User was successfully updated.' } - format.json { render :json => @user, :status => :ok } - else - format.html { render :action => "edit" } - format.json { render :json => @user.errors, :status => :unprocessable_entity } end + + # send inviteation if needed + if params[:invite] + +# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII') +# exit '123' + end + render :json => @user, :status => :created + else + render :json => @user.errors, :status => :unprocessable_entity + end + end + + # PUT /users/1 + def update + @user = User.find(params[:id]) + + if @user.update_attributes(params[:user]) + if params[:role_ids] + @user.role_ids = params[:role_ids] + end + if params[:group_ids] + @user.group_ids = params[:group_ids] + end + render :json => @user, :status => :ok + else + render :json => @user.errors, :status => :unprocessable_entity end end # DELETE /users/1 - # DELETE /users/1.json def destroy @user = User.find(params[:id]) @user.destroy - respond_to do |format| - format.html { redirect_to users_url } - format.json { head :ok } - end + head :ok end end