Code cleanup, we only use json as backend.

This commit is contained in:
Martin Edenhofer 2012-04-12 13:27:01 +02:00
parent a7bfbccd99
commit 9903473076
9 changed files with 139 additions and 374 deletions

View file

@ -2,85 +2,47 @@ class GroupsController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /groups # GET /groups
# GET /groups.json
def index def index
@groups = Group.all @groups = Group.all
respond_to do |format| render :json => @groups
format.html # index.html.erb
format.json { render :json => @groups }
end
end end
# GET /groups/1 # GET /groups/1
# GET /groups/1.json
def show def show
@group = Group.find(params[:id]) @group = Group.find(params[:id])
respond_to do |format| render :json => @group
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])
end end
# POST /groups # POST /groups
# POST /groups.json
def create def create
@group = Group.new(params[:group]) @group = Group.new(params[:group])
@group.created_by_id = current_user.id @group.created_by_id = current_user.id
respond_to do |format|
if @group.save if @group.save
format.html { redirect_to @group, :notice => 'Group was successfully created.' } render :json => @group, :status => :created
format.json { render :json => @group, :status => :created }
else else
format.html { render :action => "new" } render :json => @group.errors, :status => :unprocessable_entity
format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
end end
end end
# PUT /groups/1 # PUT /groups/1
# PUT /groups/1.json
def update def update
@group = Group.find(params[:id]) @group = Group.find(params[:id])
respond_to do |format|
if @group.update_attributes(params[:group]) if @group.update_attributes(params[:group])
format.html { redirect_to @group, :notice => 'Group was successfully updated.' } render :json => @group, :status => :ok
format.json { render :json => @group, :status => :ok }
else else
format.html { render :action => "edit" } render :json => @group.errors, :status => :unprocessable_entity
format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
end end
end end
# DELETE /groups/1 # DELETE /groups/1
# DELETE /groups/1.json
def destroy def destroy
@group = Group.find(params[:id]) @group = Group.find(params[:id])
@group.destroy @group.destroy
respond_to do |format| head :ok
format.html { redirect_to groups_url }
format.json { head :ok }
end
end end
end end

View file

@ -2,85 +2,47 @@ class OrganizationsController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /organizations # GET /organizations
# GET /organizations.json
def index def index
@organizations = Organization.all @organizations = Organization.all
respond_to do |format| render :json => @organizations
format.html # index.html.erb
format.json { render :json => @organizations }
end
end end
# GET /organizations/1 # GET /organizations/1
# GET /organizations/1.json
def show def show
@organization = Organization.find(params[:id]) @organization = Organization.find(params[:id])
respond_to do |format| render :json => @organization
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])
end end
# POST /organizations # POST /organizations
# POST /organizations.json
def create def create
@organization = Organization.new(params[:organization]) @organization = Organization.new(params[:organization])
@organization.created_by_id = current_user.id @organization.created_by_id = current_user.id
respond_to do |format|
if @organization.save if @organization.save
format.html { redirect_to @organization, :notice => 'Organization was successfully created.' } render :json => @organization, :status => :created
format.json { render :json => @organization, :status => :created }
else else
format.html { render :action => "new" } render :json => @organization.errors, :status => :unprocessable_entity
format.json { render :json => @organization.errors, :status => :unprocessable_entity }
end
end end
end end
# PUT /organizations/1 # PUT /organizations/1
# PUT /organizations/1.json
def update def update
@organization = Organization.find(params[:id]) @organization = Organization.find(params[:id])
respond_to do |format|
if @organization.update_attributes(params[:organization]) if @organization.update_attributes(params[:organization])
format.html { redirect_to @organization, :notice => 'Organization was successfully updated.' } render :json => @organization, :status => :ok
format.json { render :json => @organization, :status => :ok }
else else
format.html { render :action => "edit" } render :json => @organization.errors, :status => :unprocessable_entity
format.json { render :json => @organization.errors, :status => :unprocessable_entity }
end
end end
end end
# DELETE /organizations/1 # DELETE /organizations/1
# DELETE /organizations/1.json
def destroy def destroy
@organization = Organization.find(params[:id]) @organization = Organization.find(params[:id])
@organization.destroy @organization.destroy
respond_to do |format| head :ok
format.html { redirect_to organizations_url }
format.json { head :ok }
end
end end
end end

View file

@ -2,85 +2,54 @@ class RolesController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /roles # GET /roles
# GET /roles.json
def index def index
@roles = Role.all @roles = Role.all
respond_to do |format| render :json => @roles
format.html # index.html.erb
format.json { render :json => @roles }
end
end end
# GET /roles/1 # GET /roles/1
# GET /roles/1.json
def show def show
@role = Role.find(params[:id]) @role = Role.find(params[:id])
respond_to do |format| render :json => @role
format.html # show.html.erb
format.json { render :json => @role }
end
end end
# GET /roles/new # GET /roles/new
# GET /roles/new.json
def new def new
@role = Role.new @role = Role.new
respond_to do |format| render :json => @role
format.html # new.html.erb
format.json { render :json => @role }
end
end
# GET /roles/1/edit
def edit
@role = Role.find(params[:id])
end end
# POST /roles # POST /roles
# POST /roles.json
def create def create
@role = Role.new(params[:role]) @role = Role.new(params[:role])
@role.created_by_id = current_user.id @role.created_by_id = current_user.id
respond_to do |format|
if @role.save if @role.save
format.html { redirect_to @role, :notice => 'Role was successfully created.' } render :json => @role, :status => :created
format.json { render :json => @role, :status => :created }
else else
format.html { render :action => "new" } render :json => @role.errors, :status => :unprocessable_entity
format.json { render :json => @role.errors, :status => :unprocessable_entity }
end
end end
end end
# PUT /roles/1 # PUT /roles/1
# PUT /roles/1.json
def update def update
@role = Role.find(params[:id]) @role = Role.find(params[:id])
respond_to do |format|
if @role.update_attributes(params[:role]) if @role.update_attributes(params[:role])
format.html { redirect_to @role, :notice => 'Role was successfully updated.' } render :json => @role, :status => :ok
format.json { render :json => @role, :status => :ok }
else else
format.html { render :action => "edit" } render :json => @role.errors, :status => :unprocessable_entity
format.json { render :json => @role.errors, :status => :unprocessable_entity }
end
end end
end end
# DELETE /roles/1 # DELETE /roles/1
# DELETE /roles/1.json
def destroy def destroy
@role = Role.find(params[:id]) @role = Role.find(params[:id])
@role.destroy @role.destroy
respond_to do |format| head :ok
format.html { redirect_to roles_url }
format.json { head :ok }
end
end end
end end

View file

@ -2,76 +2,46 @@ class SettingsController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /settings # GET /settings
# GET /settings.json
def index def index
@settings = Setting.all @settings = Setting.all
respond_to do |format| render :json => @settings
format.json { render :json => @settings }
end
end end
# GET /settings/1 # GET /settings/1
# GET /settings/1.json
def show def show
@setting = Setting.find(params[:id]) @setting = Setting.find(params[:id])
respond_to do |format| render :json => @setting
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])
end end
# POST /settings # POST /settings
# POST /settings.json
def create def create
@setting = Setting.new(params[:setting]) @setting = Setting.new(params[:setting])
respond_to do |format|
if @setting.save if @setting.save
format.json { render :json => @setting, :status => :created } render :json => @setting, :status => :created
else else
format.json { render :json => @setting.errors, :status => :unprocessable_entity } render :json => @setting.errors, :status => :unprocessable_entity
end
end end
end end
# PUT /settings/1 # PUT /settings/1
# PUT /settings/1.json
def update def update
@setting = Setting.find(params[:id]) @setting = Setting.find(params[:id])
respond_to do |format|
if @setting.update_attributes(params[:setting]) if @setting.update_attributes(params[:setting])
format.json { render :json => @setting, :status => :ok } render :json => @setting, :status => :ok
else else
format.json { render :json => @setting.errors, :status => :unprocessable_entity } render :json => @setting.errors, :status => :unprocessable_entity
end
end end
end end
# DELETE /settings/1 # DELETE /settings/1
# DELETE /settings/1.json
def destroy def destroy
@setting = Setting.find(params[:id]) @setting = Setting.find(params[:id])
@setting.destroy @setting.destroy
respond_to do |format| head :ok
format.json { head :ok }
end
end end
end end

View file

@ -2,27 +2,20 @@ class TicketArticlesController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /articles # GET /articles
# GET /articles.json
def index def index
@articles = Ticket::Article.all @articles = Ticket::Article.all
respond_to do |format| render :json => @articles
format.json { render :json => @articles }
end
end end
# GET /articles/1 # GET /articles/1
# GET /articles/1.json
def show def show
@article = Ticket::Article.find(params[:id]) @article = Ticket::Article.find(params[:id])
respond_to do |format| render :json => @article
format.json { render :json => @article }
end
end end
# POST /articles # POST /articles
# POST /articles.json
def create def create
@article = Ticket::Article.new(params[:ticket_article]) @article = Ticket::Article.new(params[:ticket_article])
@article.created_by_id = current_user.id @article.created_by_id = current_user.id
@ -33,9 +26,8 @@ class TicketArticlesController < ApplicationController
:o_id => @article.ticket_id :o_id => @article.ticket_id
) )
respond_to do |format|
if @article.save if @article.save
format.json { render :json => @article, :status => :created } render :json => @article, :status => :created
# remove attachments from upload cache # remove attachments from upload cache
Store.remove( Store.remove(
@ -43,33 +35,26 @@ class TicketArticlesController < ApplicationController
:o_id => @article.ticket_id :o_id => @article.ticket_id
) )
else else
format.json { render :json => @article.errors, :status => :unprocessable_entity } render :json => @article.errors, :status => :unprocessable_entity
end
end end
end end
# PUT /articles/1 # PUT /articles/1
# PUT /articles/1.json
def update def update
@article = Ticket::Article.find(params[:id]) @article = Ticket::Article.find(params[:id])
respond_to do |format|
if @article.update_attributes(params[:ticket_article]) if @article.update_attributes(params[:ticket_article])
format.json { render :json => @article, :status => :ok } render :json => @article, :status => :ok
else else
format.json { render :json => @article.errors, :status => :unprocessable_entity } render :json => @article.errors, :status => :unprocessable_entity
end
end end
end end
# DELETE /articles/1 # DELETE /articles/1
# DELETE /articles/1.json
def destroy def destroy
@article = Ticket::Article.find(params[:id]) @article = Ticket::Article.find(params[:id])
@article.destroy @article.destroy
respond_to do |format| head :ok
format.json { head :ok }
end
end end
end end

View file

@ -2,61 +2,46 @@ class TicketPrioritiesController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /ticket_priorities # GET /ticket_priorities
# GET /ticket_priorities.json
def index def index
@ticket_priorities = Ticket::Priority.all @ticket_priorities = Ticket::Priority.all
respond_to do |format| render :json => @ticket_priorities
format.json { render :json => @ticket_priorities }
end
end end
# GET /ticket_priorities/1 # GET /ticket_priorities/1
# GET /ticket_priorities/1.json
def show def show
@ticket_priority = Ticket::Priority.find(params[:id]) @ticket_priority = Ticket::Priority.find(params[:id])
respond_to do |format| render :json => @ticket_priority
format.json { render :json => @ticket_priority }
end
end end
# POST /ticket_priorities # POST /ticket_priorities
# POST /ticket_priorities.json
def create def create
@ticket_priority = Ticket::Priority.new(params[:ticket_priority]) @ticket_priority = Ticket::Priority.new(params[:ticket_priority])
respond_to do |format|
if @ticket_priority.save if @ticket_priority.save
format.json { render :json => @ticket_priority, :status => :created } render :json => @ticket_priority, :status => :created
else else
format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity } render :json => @ticket_priority.errors, :status => :unprocessable_entity
end
end end
end end
# PUT /ticket_priorities/1 # PUT /ticket_priorities/1
# PUT /ticket_priorities/1.json
def update def update
@ticket_priority = Ticket::Priority.find(params[:id]) @ticket_priority = Ticket::Priority.find(params[:id])
respond_to do |format|
if @ticket_priority.update_attributes(params[:ticket_priority]) if @ticket_priority.update_attributes(params[:ticket_priority])
format.json { render :json => @ticket_priority, :status => :ok } render :json => @ticket_priority, :status => :ok
else else
format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity } render :json => @ticket_priority.errors, :status => :unprocessable_entity
end
end end
end end
# DELETE /ticket_priorities/1 # DELETE /ticket_priorities/1
# DELETE /ticket_priorities/1.json
def destroy def destroy
@ticket_priority = Ticket::Priority.find(params[:id]) @ticket_priority = Ticket::Priority.find(params[:id])
@ticket_priority.destroy @ticket_priority.destroy
respond_to do |format| head :ok
format.json { head :ok }
end
end end
end end

View file

@ -2,61 +2,46 @@ class TicketStatesController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /ticket_states # GET /ticket_states
# GET /ticket_states.json
def index def index
@ticket_states = Ticket::State.all @ticket_states = Ticket::State.all
respond_to do |format| render :json => @ticket_states
format.json { render :json => @ticket_states }
end
end end
# GET /ticket_states/1 # GET /ticket_states/1
# GET /ticket_states/1.json
def show def show
@ticket_state = Ticket::State.find(params[:id]) @ticket_state = Ticket::State.find(params[:id])
respond_to do |format| render :json => @ticket_state
format.json { render :json => @ticket_state }
end
end end
# POST /ticket_states # POST /ticket_states
# POST /ticket_states.json
def create def create
@ticket_state = Ticket::State.new(params[:ticket_state]) @ticket_state = Ticket::State.new(params[:ticket_state])
respond_to do |format|
if @ticket_state.save if @ticket_state.save
format.json { render :json => @ticket_state, :status => :created } render :json => @ticket_state, :status => :created
else else
format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity } render :json => @ticket_state.errors, :status => :unprocessable_entity
end
end end
end end
# PUT /ticket_states/1 # PUT /ticket_states/1
# PUT /ticket_states/1.json
def update def update
@ticket_state = Ticket::State.find(params[:id]) @ticket_state = Ticket::State.find(params[:id])
respond_to do |format|
if @ticket_state.update_attributes(params[:ticket_state]) if @ticket_state.update_attributes(params[:ticket_state])
format.json { render :json => @ticket_state, :status => :ok } render :json => @ticket_state, :status => :ok
else else
format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity } render :json => @ticket_state.errors, :status => :unprocessable_entity
end
end end
end end
# DELETE /ticket_states/1 # DELETE /ticket_states/1
# DELETE /ticket_states/1.json
def destroy def destroy
@ticket_state = Ticket::State.find(params[:id]) @ticket_state = Ticket::State.find(params[:id])
@ticket_state.destroy @ticket_state.destroy
respond_to do |format| head :ok
format.json { head :ok }
end
end end
end end

View file

@ -2,62 +2,47 @@ class TicketsController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /tickets # GET /tickets
# GET /tickets.json
def index def index
@tickets = Ticket.all @tickets = Ticket.all
respond_to do |format| render :json => @tickets
format.json { render :json => @tickets }
end
end end
# GET /tickets/1 # GET /tickets/1
# GET /tickets/1.json
def show def show
@ticket = Ticket.find(params[:id]) @ticket = Ticket.find(params[:id])
respond_to do |format| render :json => @ticket
format.json { render :json => @ticket }
end
end end
# POST /tickets # POST /tickets
# POST /tickets.json
def create def create
@ticket = Ticket.new(params[:ticket]) @ticket = Ticket.new(params[:ticket])
@ticket.created_by_id = current_user.id @ticket.created_by_id = current_user.id
respond_to do |format|
if @ticket.save if @ticket.save
format.json { render :json => @ticket, :status => :created } render :json => @ticket, :status => :created
else else
format.json { render :json => @ticket.errors, :status => :unprocessable_entity } render :json => @ticket.errors, :status => :unprocessable_entity
end
end end
end end
# PUT /tickets/1 # PUT /tickets/1
# PUT /tickets/1.json
def update def update
@ticket = Ticket.find(params[:id]) @ticket = Ticket.find(params[:id])
respond_to do |format|
if @ticket.update_attributes(params[:ticket]) if @ticket.update_attributes(params[:ticket])
format.json { render :json => @ticket, :status => :ok } render :json => @ticket, :status => :ok
else else
format.json { render :json => @ticket.errors, :status => :unprocessable_entity } render :json => @ticket.errors, :status => :unprocessable_entity
end
end end
end end
# DELETE /tickets/1 # DELETE /tickets/1
# DELETE /tickets/1.json
def destroy def destroy
@ticket = Ticket.find(params[:id]) @ticket = Ticket.find(params[:id])
@ticket.destroy @ticket.destroy
respond_to do |format| head :ok
format.json { head :ok }
end
end end
end end

View file

@ -2,7 +2,6 @@ class UsersController < ApplicationController
before_filter :authentication_check, :except => [:create] before_filter :authentication_check, :except => [:create]
# GET /users # GET /users
# GET /users.json
def index def index
@users = User.all @users = User.all
@ -17,46 +16,21 @@ class UsersController < ApplicationController
i[:organization_id] = organization_id i[:organization_id] = organization_id
} }
respond_to do |format| render :json => @users
format.html # index.html.erb
format.json { render :json => @users }
end
end end
# GET /users/1 # GET /users/1
# GET /users/1.json
def show def show
# @user = User.find(params[:id]) # @user = User.find(params[:id])
@user = user_data_full(params[:id]) @user = user_data_full(params[:id])
respond_to do |format| render :json => @user
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])
end end
# POST /users # POST /users
# POST /users.json
def create def create
@user = User.new(params[:user]) @user = User.new(params[:user])
@user.created_by_id = (current_user && current_user.id) || 1 @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 it's a signup, add user to customer role
@ -89,21 +63,16 @@ class UsersController < ApplicationController
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII') # logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
# exit '123' # exit '123'
end end
format.html { redirect_to @user, :notice => 'User was successfully created.' } render :json => @user, :status => :created
format.json { render :json => @user, :status => :created }
else else
format.html { render :action => "new" } render :json => @user.errors, :status => :unprocessable_entity
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end end
end end
# PUT /users/1 # PUT /users/1
# PUT /users/1.json
def update def update
@user = User.find(params[:id]) @user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
if params[:role_ids] if params[:role_ids]
@user.role_ids = params[:role_ids] @user.role_ids = params[:role_ids]
@ -111,24 +80,17 @@ class UsersController < ApplicationController
if params[:group_ids] if params[:group_ids]
@user.group_ids = params[:group_ids] @user.group_ids = params[:group_ids]
end end
format.html { redirect_to @user, :notice => 'User was successfully updated.' } render :json => @user, :status => :ok
format.json { render :json => @user, :status => :ok }
else else
format.html { render :action => "edit" } render :json => @user.errors, :status => :unprocessable_entity
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end end
end end
# DELETE /users/1 # DELETE /users/1
# DELETE /users/1.json
def destroy def destroy
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.destroy @user.destroy
respond_to do |format| head :ok
format.html { redirect_to users_url }
format.json { head :ok }
end
end end
end end