Init version of package manager.

This commit is contained in:
Martin Edenhofer 2012-12-27 21:17:33 +01:00
parent 17e3ce1766
commit 07c8b79721
17 changed files with 158 additions and 2 deletions

View file

@ -0,0 +1,28 @@
class Index extends App.Controller
constructor: ->
super
# check authentication
return if !@authenticate()
App.Com.ajax(
id: 'packages',
type: 'GET',
url: '/api/packages',
processData: true,
success: (data) =>
@render(data)
)
render: (data) ->
@html App.view('package')(
head: 'Dashboard'
packages: data.packages
)
App.Config.set( 'package', Index, 'Routes' )
App.Config.set( 'Packages', { prio: 1800, parent: '#settings', name: 'Packages', target: '#package', role: ['Admin'] }, 'NavBar' )

View file

@ -62,4 +62,3 @@ App.Config.set( 'System', { prio: 1400, parent: '#settings', name: 'System', tar
App.Config.set( 'Security', { prio: 1500, parent: '#settings', name: 'Security', target: '#settings/security', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Security', { prio: 1500, parent: '#settings', name: 'Security', target: '#settings/security', role: ['Admin'] }, 'NavBar' )
App.Config.set( 'Ticket', { prio: 1600, parent: '#settings', name: 'Ticket', target: '#settings/ticket', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Ticket', { prio: 1600, parent: '#settings', name: 'Ticket', target: '#settings/ticket', role: ['Admin'] }, 'NavBar' )
App.Config.set( 'Object', { prio: 1700, parent: '#settings', name: 'Objects', target: '#settings/objects', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Object', { prio: 1700, parent: '#settings', name: 'Objects', target: '#settings/objects', role: ['Admin'] }, 'NavBar' )
App.Config.set( 'Packages', { prio: 1800, parent: '#settings', name: 'Packages', target: '#packages', role: ['Admin'] }, 'NavBar' )

View file

@ -0,0 +1,33 @@
<div class="page-header">
<h1><%- @T( 'Package' ) %> <small><%- @T( 'Management' ) %></small></h1>
</div>
<div class="row">
<div class="span3">
<ul class="nav nav-tabs nav-stacked">
<li class=""><a data-type="" ><%- @T( 'Installed' ) %></a></li>
<li class=""><a data-type="" ><%- @T( 'Upload' ) %></a></li>
</ul>
</div>
<div class="span9">
<table class="table table-striped table-hover">
<thead>
<th><%- @T('Name') %></th>
<th><%- @T('Version') %></th>
<th><%- @T('Vendor') %></th>
<th><%- @T('Action') %></th>
</thead>
<tbody>
<% for item in @packages: %>
<tr><%= item.name %></tr>
<tr><%= item.version %></tr>
<tr><a href="<%- item.url %>" target="_blank"><%= item.vendor %></a></tr>
<tr>-</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View file

@ -167,6 +167,12 @@ class ApplicationController < ActionController::Base
return false return false
end end
def is_not_role( role_name )
return false if is_role( role_name )
response_access_deny()
return true
end
def response_access_deny def response_access_deny
render( render(
:json => {}, :json => {},

View file

@ -149,6 +149,7 @@ curl http://localhost/api/channels.json -v -u #{login}:#{password} -H "Content-T
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(Channel, params) model_create_render(Channel, params)
end end
@ -185,6 +186,7 @@ curl http://localhost/api/channels.json -v -u #{login}:#{password} -H "Content-T
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(Channel, params) model_update_render(Channel, params)
end end
@ -202,6 +204,7 @@ curl http://localhost/api/channels.json -v -u #{login}:#{password} -H "Content-T
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Channel, params) model_destory_render(Channel, params)
end end
end end

View file

@ -95,6 +95,7 @@ curl http://localhost/api/email_addresses.json -v -u #{login}:#{password} -H "Co
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(EmailAddress, params) model_create_render(EmailAddress, params)
end end
@ -125,6 +126,7 @@ curl http://localhost/api/email_addresses.json -v -u #{login}:#{password} -H "Co
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(EmailAddress, params) model_update_render(EmailAddress, params)
end end
@ -139,6 +141,7 @@ Test:
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(EmailAddress, params) model_destory_render(EmailAddress, params)
end end
end end

View file

@ -99,6 +99,7 @@ curl http://localhost/api/groups.json -v -u #{login}:#{password} -H "Content-Typ
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(Group, params) model_create_render(Group, params)
end end
@ -130,6 +131,7 @@ curl http://localhost/api/groups.json -v -u #{login}:#{password} -H "Content-Typ
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(Group, params) model_update_render(Group, params)
end end
@ -144,6 +146,7 @@ Test:
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Group, params) model_destory_render(Group, params)
end end
end end

View file

@ -0,0 +1,42 @@
class PackagesController < ApplicationController
before_filter :authentication_check
# GET /api/packages
def index
return if is_not_role('Admin')
packages = Package.all
render :json => {
:packages => packages
}
end
# POST /api/packages
def create
return if is_not_role('Admin')
content_type = request[:content_type]
puts 'content_type: ' + content_type.inspect
if !content_type || content_type == 'application/octet-stream'
if MIME::Types.type_for(params[:qqfile]).first
content_type = MIME::Types.type_for(params[:qqfile]).first.content_type
else
content_type = 'application/octet-stream'
end
end
headers_store = {
'Content-Type' => content_type
}
Store.add(
:object => 'PackageUploadCache',
:o_id => params[:form_id],
:data => request.body.read,
:filename => params[:qqfile],
:preferences => headers_store
)
# return result
render :json => {
:success => true,
}
end
end

View file

@ -117,6 +117,7 @@ curl http://localhost/api/postmaster_filters.json -v -u #{login}:#{password} -H
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(PostmasterFilter, params) model_create_render(PostmasterFilter, params)
end end
@ -159,6 +160,7 @@ curl http://localhost/api/postmaster_filters.json -v -u #{login}:#{password} -H
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(PostmasterFilter, params) model_update_render(PostmasterFilter, params)
end end
@ -173,6 +175,7 @@ Test:
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(PostmasterFilter, params) model_destory_render(PostmasterFilter, params)
end end
end end

View file

@ -93,6 +93,7 @@ curl http://localhost/api/roles.json -v -u #{login}:#{password} -H "Content-Type
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(Role, params) model_create_render(Role, params)
end end
@ -121,6 +122,7 @@ curl http://localhost/api/roles.json -v -u #{login}:#{password} -H "Content-Type
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(Role, params) model_update_render(Role, params)
end end
@ -135,6 +137,7 @@ Test:
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Role, params) model_destory_render(Role, params)
end end
end end

View file

@ -13,16 +13,19 @@ class SettingsController < ApplicationController
# POST /settings # POST /settings
def create def create
return if is_not_role('Admin')
model_create_render(Setting, params) model_create_render(Setting, params)
end end
# PUT /settings/1 # PUT /settings/1
def update def update
return if is_not_role('Admin')
model_update_render(Setting, params) model_update_render(Setting, params)
end end
# DELETE /settings/1 # DELETE /settings/1
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Setting, params) model_destory_render(Setting, params)
end end
end end

View file

@ -94,6 +94,7 @@ curl http://localhost/api/signatures.json -v -u #{login}:#{password} -H "Content
=end =end
def create def create
return if is_not_role('Admin')
model_create_render(Signature, params) model_create_render(Signature, params)
end end
@ -122,6 +123,7 @@ curl http://localhost/api/signatures.json -v -u #{login}:#{password} -H "Content
=end =end
def update def update
return if is_not_role('Admin')
model_update_render(Signature, params) model_update_render(Signature, params)
end end
@ -136,6 +138,7 @@ Test:
=end =end
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Signature, params) model_destory_render(Signature, params)
end end
end end

View file

@ -1,7 +1,7 @@
class TicketOverviewsController < ApplicationController class TicketOverviewsController < ApplicationController
before_filter :authentication_check before_filter :authentication_check
# GET /tickets # GET /api/tickets
def show def show
#sleep 2 #sleep 2

View file

@ -13,16 +13,19 @@ class TicketPrioritiesController < ApplicationController
# POST /ticket_priorities # POST /ticket_priorities
def create def create
return if is_not_role('Admin')
model_create_render(Ticket::Priority, params) model_create_render(Ticket::Priority, params)
end end
# PUT /ticket_priorities/1 # PUT /ticket_priorities/1
def update def update
return if is_not_role('Admin')
model_update_render(Ticket::Priority, params) model_update_render(Ticket::Priority, params)
end end
# DELETE /ticket_priorities/1 # DELETE /ticket_priorities/1
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Ticket::Priority, params) model_destory_render(Ticket::Priority, params)
end end
end end

View file

@ -13,16 +13,19 @@ class TicketStatesController < ApplicationController
# POST /ticket_states # POST /ticket_states
def create def create
return if is_not_role('Admin')
model_create_render(Ticket::State, params) model_create_render(Ticket::State, params)
end end
# PUT /ticket_states/1 # PUT /ticket_states/1
def update def update
return if is_not_role('Admin')
model_update_render(Ticket::State, params) model_update_render(Ticket::State, params)
end end
# DELETE /ticket_states/1 # DELETE /ticket_states/1
def destroy def destroy
return if is_not_role('Admin')
model_destory_render(Ticket::State, params) model_destory_render(Ticket::State, params)
end end
end end

View file

@ -39,4 +39,15 @@ class ApplicationModel < ActiveRecord::Base
key = self.to_s + '::' + data_id.to_s key = self.to_s + '::' + data_id.to_s
Cache.get( key.to_s ) Cache.get( key.to_s )
end end
def self.create_if_not_exists(data)
if data[:name]
record = self.where( :name => data[:name] ).first
return record if record
elsif data[:locale] && data[:source]
record = self.where( :locale => data[:locale], :source => data[:source] ).first
return record if record
end
self.create(data)
end
end end

10
config/routes/package.rb Normal file
View file

@ -0,0 +1,10 @@
module ExtraRoutes
def add(map)
# overviews
map.match '/api/packages', :to => 'packages#index', :via => :get
map.match '/api/packages', :to => 'packages#create', :via => :post
end
module_function :add
end