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
# 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 }
render :json => @group, :status => :created
else
format.html { render :action => "new" }
format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
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 }
render :json => @group, :status => :ok
else
format.html { render :action => "edit" }
format.json { render :json => @group.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @organization, :status => :created
else
format.html { render :action => "new" }
format.json { render :json => @organization.errors, :status => :unprocessable_entity }
end
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 }
render :json => @organization, :status => :ok
else
format.html { render :action => "edit" }
format.json { render :json => @organization.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @role, :status => :created
else
format.html { render :action => "new" }
format.json { render :json => @role.errors, :status => :unprocessable_entity }
end
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 }
render :json => @role, :status => :ok
else
format.html { render :action => "edit" }
format.json { render :json => @role.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @setting, :status => :created
else
format.json { render :json => @setting.errors, :status => :unprocessable_entity }
end
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 }
render :json => @setting, :status => :ok
else
format.json { render :json => @setting.errors, :status => :unprocessable_entity }
end
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

View file

@ -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,9 +26,8 @@ class TicketArticlesController < ApplicationController
:o_id => @article.ticket_id
)
respond_to do |format|
if @article.save
format.json { render :json => @article, :status => :created }
render :json => @article, :status => :created
# remove attachments from upload cache
Store.remove(
@ -43,33 +35,26 @@ class TicketArticlesController < ApplicationController
:o_id => @article.ticket_id
)
else
format.json { render :json => @article.errors, :status => :unprocessable_entity }
end
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 }
render :json => @article, :status => :ok
else
format.json { render :json => @article.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @ticket_priority, :status => :created
else
format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity }
end
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 }
render :json => @ticket_priority, :status => :ok
else
format.json { render :json => @ticket_priority.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @ticket_state, :status => :created
else
format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity }
end
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 }
render :json => @ticket_state, :status => :ok
else
format.json { render :json => @ticket_state.errors, :status => :unprocessable_entity }
end
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

View file

@ -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 }
render :json => @ticket, :status => :created
else
format.json { render :json => @ticket.errors, :status => :unprocessable_entity }
end
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 }
render :json => @ticket, :status => :ok
else
format.json { render :json => @ticket.errors, :status => :unprocessable_entity }
end
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

View file

@ -2,7 +2,6 @@ class UsersController < ApplicationController
before_filter :authentication_check, :except => [:create]
# GET /users
# GET /users.json
def index
@users = User.all
@ -17,46 +16,21 @@ 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 it's a signup, add user to customer role
@ -89,21 +63,16 @@ class UsersController < ApplicationController
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
# exit '123'
end
format.html { redirect_to @user, :notice => 'User was successfully created.' }
format.json { render :json => @user, :status => :created }
render :json => @user, :status => :created
else
format.html { render :action => "new" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
render :json => @user.errors, :status => :unprocessable_entity
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]
@ -111,24 +80,17 @@ class UsersController < ApplicationController
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 }
render :json => @user, :status => :ok
else
format.html { render :action => "edit" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
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