Code cleanup.
This commit is contained in:
parent
870df3af0f
commit
286c16c3e1
5 changed files with 139 additions and 160 deletions
|
@ -1,10 +1,4 @@
|
|||
$ = jQuery.sub()
|
||||
Note = App.Note
|
||||
|
||||
$.fn.item = ->
|
||||
elementID = $(@).data('id')
|
||||
elementID or= $(@).parents('[data-id]').data('id')
|
||||
Note.find(elementID)
|
||||
|
||||
class App.Navigation extends Spine.Controller
|
||||
events:
|
||||
|
@ -21,13 +15,14 @@ class App.Navigation extends Spine.Controller
|
|||
Spine.bind 'navrebuild', (user) =>
|
||||
@log 'navbarrebuild', user
|
||||
@render(user)
|
||||
@delay( @sync, 1600 )
|
||||
|
||||
Spine.bind 'navupdate_remote', (user) =>
|
||||
@log 'navupdate_remote'
|
||||
@sync
|
||||
|
||||
# rerender if new overview data is there
|
||||
@delay( @sync, 1800 )
|
||||
@delay( @sync, 1600 )
|
||||
|
||||
render: (user) ->
|
||||
# @log 'nav render', Config.NavBar
|
||||
|
|
|
@ -14,11 +14,9 @@ class Index extends App.Controller
|
|||
|
||||
# set title
|
||||
@title 'Sign up'
|
||||
|
||||
@render()
|
||||
|
||||
@navupdate '#signup'
|
||||
|
||||
@render()
|
||||
|
||||
render: ->
|
||||
|
||||
|
@ -108,8 +106,3 @@ class Index extends App.Controller
|
|||
)
|
||||
|
||||
Config.Routes['signup'] = Index
|
||||
|
||||
#class App.SignUp extends App.Router
|
||||
# routes:
|
||||
# 'signup': Index
|
||||
#Config.Controller.push App.SignUp
|
|
@ -3,65 +3,11 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery
|
||||
# http_basic_authenticate_with :name => "test", :password => "ttt"
|
||||
|
||||
helper_method :current_user, :authentication_check
|
||||
helper_method :current_user, :authentication_check, :config_frontend, :user_data_full
|
||||
|
||||
before_filter :set_user, :cors_preflight_check
|
||||
after_filter :set_access_control_headers
|
||||
|
||||
def user_data_full (user_id)
|
||||
|
||||
# get user
|
||||
user = User.find(user_id)
|
||||
|
||||
# get linked accounts
|
||||
user['accounts'] = {}
|
||||
authorizations = user.authorizations() || []
|
||||
authorizations.each do | authorization |
|
||||
user['accounts'][authorization.provider] = {
|
||||
:uid => authorization[:uid],
|
||||
:username => authorization[:username]
|
||||
}
|
||||
end
|
||||
|
||||
# do not show password
|
||||
user['password'] = ''
|
||||
|
||||
# show linked topics and items
|
||||
user['links'] = []
|
||||
ticket_state_list_open = Ticket::State.where( :ticket_state_type_id => Ticket::StateType.where(:name => ['new','open', 'pending remidner', 'pending action']) )
|
||||
ticket_state_list_closed = Ticket::State.where( :ticket_state_type_id => Ticket::StateType.where(:name => ['closed'] ) )
|
||||
|
||||
tickets_open = Ticket.where(:customer_id => user_id, :ticket_state_id => ticket_state_list_open).count()
|
||||
tickets_closed = Ticket.where(:customer_id => user_id, :ticket_state_id => ticket_state_list_closed).count()
|
||||
|
||||
topic = {
|
||||
:title => 'Tickets',
|
||||
:items => [
|
||||
{
|
||||
:url => '',
|
||||
:name => 'open (' + tickets_open.to_s + ')',
|
||||
:title => 'Open Tickets',
|
||||
:class => 'user-tickets',
|
||||
:data => 'open'
|
||||
},
|
||||
{
|
||||
:url => '',
|
||||
:name => 'closed (' + tickets_closed.to_s + ')',
|
||||
:title => 'Closed Tickets',
|
||||
:class => 'user-tickets',
|
||||
:data => 'closed'
|
||||
}
|
||||
]
|
||||
}
|
||||
user['links'].push topic
|
||||
|
||||
# set roles
|
||||
user['roles'] = user.roles.select('id, name').where(:active => true)
|
||||
user['groups'] = user.groups.select('id, name').where(:active => true)
|
||||
user['organization'] = user.organization
|
||||
user['organizations'] = user.organizations.select('id, name').where(:active => true)
|
||||
return user
|
||||
end
|
||||
|
||||
# For all responses in this controller, return the CORS access control headers.
|
||||
def set_access_control_headers
|
||||
|
@ -121,15 +67,15 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# message = 'login required'
|
||||
if message != ''
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
render :json => { :error => message }, :status => :unauthorized
|
||||
}
|
||||
render(
|
||||
:json => {
|
||||
:error => message,
|
||||
},
|
||||
:status => :unauthorized
|
||||
)
|
||||
end
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end
|
||||
|
||||
# logger.debug 'session check'
|
||||
|
@ -137,17 +83,16 @@ class ApplicationController < ActionController::Base
|
|||
# session[:user_id] = 2
|
||||
if !session[:user_id]
|
||||
logger.debug '!session user_id'
|
||||
# logger.debug session.inspect
|
||||
message = 'no valid session, user_id'
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
render :json => { :error => message }, :status => :unauthorized
|
||||
}
|
||||
end
|
||||
return true
|
||||
render(
|
||||
:json => {
|
||||
:error => message,
|
||||
},
|
||||
:status => :unauthorized
|
||||
)
|
||||
return false
|
||||
end
|
||||
|
||||
# check session auth
|
||||
# return 1231
|
||||
# request_http_basic_authentication
|
||||
return false
|
||||
|
@ -181,4 +126,69 @@ class ApplicationController < ActionController::Base
|
|||
)
|
||||
end
|
||||
|
||||
def config_frontend
|
||||
|
||||
# config
|
||||
config = {}
|
||||
Setting.where( :frontend => true ).each { |setting|
|
||||
config[setting.name] = setting.state[:value]
|
||||
}
|
||||
return config
|
||||
end
|
||||
|
||||
def user_data_full (user_id)
|
||||
|
||||
# get user
|
||||
user = User.find(user_id)
|
||||
|
||||
# get linked accounts
|
||||
user['accounts'] = {}
|
||||
authorizations = user.authorizations() || []
|
||||
authorizations.each do | authorization |
|
||||
user['accounts'][authorization.provider] = {
|
||||
:uid => authorization[:uid],
|
||||
:username => authorization[:username]
|
||||
}
|
||||
end
|
||||
|
||||
# do not show password
|
||||
user['password'] = ''
|
||||
|
||||
# show linked topics and items
|
||||
user['links'] = []
|
||||
ticket_state_list_open = Ticket::State.where( :ticket_state_type_id => Ticket::StateType.where(:name => ['new','open', 'pending remidner', 'pending action']) )
|
||||
ticket_state_list_closed = Ticket::State.where( :ticket_state_type_id => Ticket::StateType.where(:name => ['closed'] ) )
|
||||
|
||||
tickets_open = Ticket.where(:customer_id => user_id, :ticket_state_id => ticket_state_list_open).count()
|
||||
tickets_closed = Ticket.where(:customer_id => user_id, :ticket_state_id => ticket_state_list_closed).count()
|
||||
|
||||
topic = {
|
||||
:title => 'Tickets',
|
||||
:items => [
|
||||
{
|
||||
:url => '',
|
||||
:name => 'open (' + tickets_open.to_s + ')',
|
||||
:title => 'Open Tickets',
|
||||
:class => 'user-tickets',
|
||||
:data => 'open'
|
||||
},
|
||||
{
|
||||
:url => '',
|
||||
:name => 'closed (' + tickets_closed.to_s + ')',
|
||||
:title => 'Closed Tickets',
|
||||
:class => 'user-tickets',
|
||||
:data => 'closed'
|
||||
}
|
||||
]
|
||||
}
|
||||
user['links'].push topic
|
||||
|
||||
# set roles
|
||||
user['roles'] = user.roles.select('id, name').where(:active => true)
|
||||
user['groups'] = user.groups.select('id, name').where(:active => true)
|
||||
user['organization'] = user.organization
|
||||
user['organizations'] = user.organizations.select('id, name').where(:active => true)
|
||||
return user
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,14 +6,13 @@ class SessionsController < ApplicationController
|
|||
# "Create" a login, aka "log the user in"
|
||||
def create
|
||||
logger.debug 'session create'
|
||||
logger.debug params.inspect
|
||||
logger.debug 'b auth'
|
||||
# logger.debug params.inspect
|
||||
user = User.authenticate( params[:username], params[:password] )
|
||||
logger.debug 'a auth'
|
||||
# user = User.authenticate('hansi', 'test')
|
||||
|
||||
respond_to do |format|
|
||||
if user
|
||||
# auth failed
|
||||
if !user
|
||||
render :json => { :error => 'login failed' }, :status => :unprocessable_entity
|
||||
end
|
||||
|
||||
# do not show password
|
||||
user['password'] = ''
|
||||
|
@ -26,32 +25,20 @@ class SessionsController < ApplicationController
|
|||
# auto population of default collections
|
||||
default_collection = default_collections()
|
||||
|
||||
# set session user_id
|
||||
session[:user_id] = user.id
|
||||
format.json { render :json => { :session => user, :default_collections => default_collection }, :status => :created }
|
||||
else
|
||||
format.json { render :json => { :error => 'login failed' }, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
# return new session data
|
||||
render :json => { :session => user, :default_collections => default_collection }, :status => :created
|
||||
end
|
||||
|
||||
def show
|
||||
logger.debug 'session show'
|
||||
logger.debug params.inspect
|
||||
# user = User.authenticate('hansi', 'test')
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
# config
|
||||
config = {}
|
||||
Setting.where( :frontend => true ).each { |setting|
|
||||
config[setting.name] = setting.state[:value]
|
||||
}
|
||||
|
||||
# no valid sessions
|
||||
if !session[:user_id]
|
||||
render :json => {
|
||||
:error => 'no valid session',
|
||||
:config => config,
|
||||
:config => config_frontend,
|
||||
}
|
||||
return
|
||||
end
|
||||
|
@ -63,24 +50,21 @@ class SessionsController < ApplicationController
|
|||
# auto population of default collections
|
||||
default_collection = default_collections()
|
||||
|
||||
#, :status => :created
|
||||
format.json {
|
||||
# return current session
|
||||
render :json => {
|
||||
:session => user,
|
||||
:default_collections => default_collection,
|
||||
:config => config,
|
||||
:config => config_frontend,
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# "Delete" a login, aka "log the user out"
|
||||
def destroy
|
||||
|
||||
# Remove the user id from the session
|
||||
@_current_user = session[:user_id] = nil
|
||||
respond_to do |format|
|
||||
format.json { render :json => { } }
|
||||
end
|
||||
|
||||
render :json => { }
|
||||
end
|
||||
|
||||
def create_omniauth
|
||||
|
|
|
@ -57,7 +57,6 @@ class CreateNetwork < ActiveRecord::Migration
|
|||
end
|
||||
add_index :network_item_comments, [:network_item_id]
|
||||
|
||||
|
||||
create_table :network_item_plus do |t|
|
||||
t.references :network_item, :null => false
|
||||
t.column :created_by_id, :integer, :null => false
|
||||
|
@ -72,7 +71,6 @@ class CreateNetwork < ActiveRecord::Migration
|
|||
end
|
||||
add_index :network_category_subscriptions, [:network_categories_id, :created_by_id], :unique => true, :name => 'index_network_category_subscriptions_on_network_c_i_and_c'
|
||||
|
||||
|
||||
create_table :network_item_subscriptions do |t|
|
||||
t.references :network_item, :null => false
|
||||
t.column :created_by_id, :integer, :null => false
|
||||
|
@ -80,7 +78,6 @@ class CreateNetwork < ActiveRecord::Migration
|
|||
end
|
||||
add_index :network_item_subscriptions, [:network_item_id, :created_by_id], :unique => true, :name => 'index_network_item_subscriptions_on_item_id_and_created_by_id'
|
||||
|
||||
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
Loading…
Reference in a new issue