加入权限控制

This commit is contained in:
Jack Zhuang 2017-12-12 18:16:06 +08:00
parent 7f926cafc6
commit 8473710291
6 changed files with 61 additions and 20 deletions

View File

@ -1,6 +1,7 @@
Creator.Objects.customers =
name: "customers"
label: "Customers"
icon: "ion-ios-people-outline"
schema:
name:
label: "Name",
@ -14,5 +15,11 @@ Creator.Objects.customers =
list_views:
default:
columns: ["name", "description", "modified"]
permissions:
default:
allowCreate: true
allowDelete: true
allowEdit: true
allowRead: true
modifyAllRecords: false
viewAllRecords: false

View File

@ -3,6 +3,8 @@ FlowRouter.route '/',
if !Meteor.userId()
FlowRouter.go '/steedos/sign-in?redirect=' + context.path;
else
Session.set("apps", ["creator"]);
FlowRouter.go '/creator'
Meteor.startup ->
Session.set("apps", ["creator"]);

View File

@ -5,14 +5,14 @@ checkUserSigned = (context, redirect) ->
FlowRouter.route '/creator',
triggersEnter: [ checkUserSigned ],
action: (params, queryParams)->
FlowRouter.go "/creator/objects/home"
FlowRouter.go "/creator/crm/customers"
FlowRouter.route '/creator/:collection_name/home',
FlowRouter.route '/creator/:app_id/:object_name',
triggersEnter: [ checkUserSigned ],
action: (params, queryParams)->
Meteor.call "creator_object_init", params.collection_name, (error, object)->
Meteor.call "creator_object_init", params.object_name, (error, object)->
if object
Creator.objectClientInit(params.collection_name, object);
Creator.objectClientInit(params.object_name, object);
BlazeLayout.render 'recordLayout',
main: "creator_list"

View File

@ -1,17 +1,22 @@
Template.creator_list.helpers
collectionName: ()->
return FlowRouter.getParam("collection_name")
return FlowRouter.getParam("object_name")
collection: ()->
return "Creator.Collections." + FlowRouter.getParam("collection_name")
return "Creator.Collections." + FlowRouter.getParam("object_name")
tabular_table: ()->
return Creator.TabularTables[FlowRouter.getParam("collection_name")]
return Creator.TabularTables[FlowRouter.getParam("object_name")]
hasPermission: (permissionName)->
permissions = Creator.Objects[FlowRouter.getParam("object_name")]?.permissions?.default
if permissions
return permissions[permissionName]
Template.creator_list.events
'click .table-creator tr': (event) ->
console.log("table-creator....")
dataTable = $(event.target).closest('table').DataTable();
rowData = dataTable.row(event.currentTarget).data()
if rowData

View File

@ -8,9 +8,11 @@
</span>
<div class="pull-right">
{{#afModal class="btn btn-primary creator-add" collection=collection operation="insert" dialogClass="modal-lg modal-body-zoom" buttonContent=insertButtonContent}}
{{_ "Create"}}
{{/afModal}}
{{#if hasPermission "allowCreate"}}
{{#afModal class="btn btn-primary creator-add" collection=collection operation="insert" dialogClass="modal-lg modal-body-zoom" buttonContent=insertButtonContent}}
{{_ "Create"}}
{{/afModal}}
{{/if}}
</div>
</div>
<div class="admin-content">

View File

@ -21,7 +21,7 @@ Creator.baseSchema =
autoform:
omit: true
modified:
type: Date,
type: "Date",
optional: true
autoform:
omit: true
@ -31,6 +31,23 @@ Creator.baseSchema =
autoform:
omit: true
last_activity:
type: Date,
optional: true
autoform:
omit: true
last_viewed:
type: Date,
optional: true
autoform:
omit: true
last_referenced:
type: Date,
optional: true
autoform:
omit: true
Meteor.startup ->
_.each Creator.Objects, (obj, collection_name)->
@ -76,15 +93,23 @@ Meteor.startup ->
Creator.getObjectSchema = (obj) ->
if obj?.schema
schema = JSON.parse(JSON.stringify(obj.schema))
schema = obj.schema
_.extend(schema, Creator.baseSchema)
return schema
Creator.getObjectColumns = (obj, list_view) ->
cols = []
_.each obj.list_views?[list_view]?.columns, (column_name)->
col = {}
col.data = column_name
col.title = obj.schema[column_name]?.label
cols.push(col)
if obj.schema[column_name]?.type
col = {}
col.title = obj.schema[column_name]?.label
col.data = column_name
col.render = (val, type, doc) ->
if (val instanceof Date)
return moment(val).format('YYYY-MM-DD H:mm')
else if (val == null)
return ""
else
return val;
cols.push(col)
return cols