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()
|
$ = 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
|
class App.Navigation extends Spine.Controller
|
||||||
events:
|
events:
|
||||||
|
@ -21,13 +15,14 @@ class App.Navigation extends Spine.Controller
|
||||||
Spine.bind 'navrebuild', (user) =>
|
Spine.bind 'navrebuild', (user) =>
|
||||||
@log 'navbarrebuild', user
|
@log 'navbarrebuild', user
|
||||||
@render(user)
|
@render(user)
|
||||||
|
@delay( @sync, 1600 )
|
||||||
|
|
||||||
Spine.bind 'navupdate_remote', (user) =>
|
Spine.bind 'navupdate_remote', (user) =>
|
||||||
@log 'navupdate_remote'
|
@log 'navupdate_remote'
|
||||||
@sync
|
@sync
|
||||||
|
|
||||||
# rerender if new overview data is there
|
# rerender if new overview data is there
|
||||||
@delay( @sync, 1800 )
|
@delay( @sync, 1600 )
|
||||||
|
|
||||||
render: (user) ->
|
render: (user) ->
|
||||||
# @log 'nav render', Config.NavBar
|
# @log 'nav render', Config.NavBar
|
||||||
|
|
|
@ -14,11 +14,9 @@ class Index extends App.Controller
|
||||||
|
|
||||||
# set title
|
# set title
|
||||||
@title 'Sign up'
|
@title 'Sign up'
|
||||||
|
|
||||||
@render()
|
|
||||||
|
|
||||||
@navupdate '#signup'
|
@navupdate '#signup'
|
||||||
|
|
||||||
|
@render()
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
|
@ -108,8 +106,3 @@ class Index extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
Config.Routes['signup'] = Index
|
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
|
protect_from_forgery
|
||||||
# http_basic_authenticate_with :name => "test", :password => "ttt"
|
# 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
|
before_filter :set_user, :cors_preflight_check
|
||||||
after_filter :set_access_control_headers
|
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.
|
# For all responses in this controller, return the CORS access control headers.
|
||||||
def set_access_control_headers
|
def set_access_control_headers
|
||||||
|
@ -121,15 +67,15 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# message = 'login required'
|
|
||||||
if message != ''
|
if message != ''
|
||||||
respond_to do |format|
|
render(
|
||||||
format.json {
|
:json => {
|
||||||
render :json => { :error => message }, :status => :unauthorized
|
:error => message,
|
||||||
}
|
},
|
||||||
end
|
:status => :unauthorized
|
||||||
|
)
|
||||||
end
|
end
|
||||||
return true
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# logger.debug 'session check'
|
# logger.debug 'session check'
|
||||||
|
@ -137,17 +83,16 @@ class ApplicationController < ActionController::Base
|
||||||
# session[:user_id] = 2
|
# session[:user_id] = 2
|
||||||
if !session[:user_id]
|
if !session[:user_id]
|
||||||
logger.debug '!session user_id'
|
logger.debug '!session user_id'
|
||||||
# logger.debug session.inspect
|
|
||||||
message = 'no valid session, user_id'
|
message = 'no valid session, user_id'
|
||||||
respond_to do |format|
|
render(
|
||||||
format.json {
|
:json => {
|
||||||
render :json => { :error => message }, :status => :unauthorized
|
:error => message,
|
||||||
}
|
},
|
||||||
end
|
:status => :unauthorized
|
||||||
return true
|
)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# check session auth
|
|
||||||
# return 1231
|
# return 1231
|
||||||
# request_http_basic_authentication
|
# request_http_basic_authentication
|
||||||
return false
|
return false
|
||||||
|
@ -178,7 +123,72 @@ class ApplicationController < ActionController::Base
|
||||||
:history_type_id => history_type.id,
|
:history_type_id => history_type.id,
|
||||||
:history_object_id => history_object.id,
|
:history_object_id => history_object.id,
|
||||||
:created_by_id => session[:user_id]
|
:created_by_id => session[:user_id]
|
||||||
)
|
)
|
||||||
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,81 +6,65 @@ class SessionsController < ApplicationController
|
||||||
# "Create" a login, aka "log the user in"
|
# "Create" a login, aka "log the user in"
|
||||||
def create
|
def create
|
||||||
logger.debug 'session create'
|
logger.debug 'session create'
|
||||||
logger.debug params.inspect
|
# logger.debug params.inspect
|
||||||
logger.debug 'b auth'
|
user = User.authenticate( params[:username], params[:password] )
|
||||||
user = User.authenticate(params[:username], params[:password])
|
|
||||||
logger.debug 'a auth'
|
|
||||||
# user = User.authenticate('hansi', 'test')
|
|
||||||
|
|
||||||
respond_to do |format|
|
# auth failed
|
||||||
if user
|
if !user
|
||||||
|
render :json => { :error => 'login failed' }, :status => :unprocessable_entity
|
||||||
# do not show password
|
|
||||||
user['password'] = ''
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
# auto population of default collections
|
|
||||||
default_collection = default_collections()
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
|
# do not show password
|
||||||
|
user['password'] = ''
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# auto population of default collections
|
||||||
|
default_collection = default_collections()
|
||||||
|
|
||||||
|
# set session user_id
|
||||||
|
session[:user_id] = user.id
|
||||||
|
|
||||||
|
# return new session data
|
||||||
|
render :json => { :session => user, :default_collections => default_collection }, :status => :created
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
logger.debug 'session show'
|
|
||||||
logger.debug params.inspect
|
|
||||||
# user = User.authenticate('hansi', 'test')
|
|
||||||
|
|
||||||
respond_to do |format|
|
# no valid sessions
|
||||||
|
if !session[:user_id]
|
||||||
# config
|
render :json => {
|
||||||
config = {}
|
:error => 'no valid session',
|
||||||
Setting.where( :frontend => true ).each { |setting|
|
:config => config_frontend,
|
||||||
config[setting.name] = setting.state[:value]
|
|
||||||
}
|
|
||||||
|
|
||||||
# no valid sessions
|
|
||||||
if !session[:user_id]
|
|
||||||
render :json => {
|
|
||||||
:error => 'no valid session',
|
|
||||||
:config => config,
|
|
||||||
}
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Save the user ID in the session so it can be used in
|
|
||||||
# subsequent requests
|
|
||||||
user = user_data_full( session[:user_id] )
|
|
||||||
|
|
||||||
# auto population of default collections
|
|
||||||
default_collection = default_collections()
|
|
||||||
|
|
||||||
#, :status => :created
|
|
||||||
format.json {
|
|
||||||
render :json => {
|
|
||||||
:session => user,
|
|
||||||
:default_collections => default_collection,
|
|
||||||
:config => config,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Save the user ID in the session so it can be used in
|
||||||
|
# subsequent requests
|
||||||
|
user = user_data_full( session[:user_id] )
|
||||||
|
|
||||||
|
# auto population of default collections
|
||||||
|
default_collection = default_collections()
|
||||||
|
|
||||||
|
# return current session
|
||||||
|
render :json => {
|
||||||
|
:session => user,
|
||||||
|
:default_collections => default_collection,
|
||||||
|
:config => config_frontend,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# "Delete" a login, aka "log the user out"
|
# "Delete" a login, aka "log the user out"
|
||||||
def destroy
|
def destroy
|
||||||
|
|
||||||
# Remove the user id from the session
|
# Remove the user id from the session
|
||||||
@_current_user = session[:user_id] = nil
|
@_current_user = session[:user_id] = nil
|
||||||
respond_to do |format|
|
|
||||||
format.json { render :json => { } }
|
render :json => { }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_omniauth
|
def create_omniauth
|
||||||
|
|
|
@ -24,9 +24,9 @@ class CreateNetwork < ActiveRecord::Migration
|
||||||
add_index :network_privacies, [:name], :unique => true
|
add_index :network_privacies, [:name], :unique => true
|
||||||
|
|
||||||
create_table :network_categories do |t|
|
create_table :network_categories do |t|
|
||||||
t.references :network_category_type, :null => false
|
t.references :network_category_type, :null => false
|
||||||
t.references :network_privacy, :null => false
|
t.references :network_privacy, :null => false
|
||||||
t.references :network, :null => false
|
t.references :network, :null => false
|
||||||
t.column :name, :string, :limit => 200, :null => false
|
t.column :name, :string, :limit => 200, :null => false
|
||||||
t.column :note, :string, :limit => 250, :null => true
|
t.column :note, :string, :limit => 250, :null => true
|
||||||
t.column :allow_comments, :boolean, :null => false, :default => true
|
t.column :allow_comments, :boolean, :null => false, :default => true
|
||||||
|
@ -41,7 +41,7 @@ class CreateNetwork < ActiveRecord::Migration
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table :network_items do |t|
|
create_table :network_items do |t|
|
||||||
t.references :network_category, :null => false
|
t.references :network_category, :null => false
|
||||||
t.column :title, :string, :limit => 200, :null => false
|
t.column :title, :string, :limit => 200, :null => false
|
||||||
t.column :body, :string, :limit => 25000, :null => false
|
t.column :body, :string, :limit => 25000, :null => false
|
||||||
t.column :created_by_id, :integer, :null => false
|
t.column :created_by_id, :integer, :null => false
|
||||||
|
@ -50,36 +50,33 @@ class CreateNetwork < ActiveRecord::Migration
|
||||||
add_index :network_items, [:network_category_id]
|
add_index :network_items, [:network_category_id]
|
||||||
|
|
||||||
create_table :network_item_comments do |t|
|
create_table :network_item_comments do |t|
|
||||||
t.references :network_item, :null => false
|
t.references :network_item, :null => false
|
||||||
t.column :body, :string, :limit => 25000, :null => false
|
t.column :body, :string, :limit => 25000, :null => false
|
||||||
t.column :created_by_id, :integer, :null => false
|
t.column :created_by_id, :integer, :null => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :network_item_comments, [:network_item_id]
|
add_index :network_item_comments, [:network_item_id]
|
||||||
|
|
||||||
|
|
||||||
create_table :network_item_plus do |t|
|
create_table :network_item_plus do |t|
|
||||||
t.references :network_item, :null => false
|
t.references :network_item, :null => false
|
||||||
t.column :created_by_id, :integer, :null => false
|
t.column :created_by_id, :integer, :null => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :network_item_plus, [:network_item_id, :created_by_id], :unique => true
|
add_index :network_item_plus, [:network_item_id, :created_by_id], :unique => true
|
||||||
|
|
||||||
create_table :network_category_subscriptions do |t|
|
create_table :network_category_subscriptions do |t|
|
||||||
t.references :network_categories, :null => false
|
t.references :network_categories, :null => false
|
||||||
t.column :created_by_id, :integer, :null => false
|
t.column :created_by_id, :integer, :null => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
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'
|
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|
|
create_table :network_item_subscriptions do |t|
|
||||||
t.references :network_item, :null => false
|
t.references :network_item, :null => false
|
||||||
t.column :created_by_id, :integer, :null => false
|
t.column :created_by_id, :integer, :null => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
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'
|
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue