大佬教程收集整理的这篇文章主要介绍了javascript – 带有alanning:meteorning app的meteor-app中的结构角色管理,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
结构体
>我使用alAnning:roles@1.2.13为应用程序添加角色管理功能.
>有四种不同的用户类型:管理员,编辑者,专家和用户.
>此外,有几个模块具有不同的内容,即汽车,数学和图像.每个模块都是用自己的流星包组织的.
>在每个模块中都有几个类别,可以由编辑者动态添加.
模块中的类别
模块的结构如下:
elementscheR_927_11845@a = new SimplescheR_927_11845@a({ element: {type: String,optional: truE} }); Cars.attachscheR_927_11845@a(new SimplescheR_927_11845@a({ title: { type: String },content: { type: String },category: { type: [elementscheR_927_11845@a],optional: true },});
如您所见,所有可用类别都在模块的Collection中.
权
>管理员:完整权利
>编辑:可以编辑所选模块中的元素(即editor_1可以编辑汽车和图像中的元素,但不能编辑数学中的元素)
>专家:可以获得完整模块的权限,也可以只获得模块的某些类别(即)expert_1可以编辑图像,但只能使用汽车中“本田”和“梅赛德斯”类别中的元素;没有编辑数学)
>用户:没有编辑
这就是我在技术上进行身份验证的方式:
router.js
var filters = { authenticate: function () { var user; if (Meteor.loggingIn()) { this.layout('login'); this.render('loading'); } else { user = Meteor.user(); if (!user) { this.layout('login'); this.render('signin'); return; } this.layout('Standard'); this.next(); } } } Router.route('/car/:_id',{ name: 'car',before: filters.authenticate,data: function () { return { cars: Cars.findOne({ _id: this.params._id }) }; } });
模板
<template name="car"> {{#if isInRole 'cars'}} Some form for ediTing {{elsE}} <h1>ReStricted area</h1> {{/if}} </template>
我把这个router.js放到每个包中.只有更改是使用每个包的集合(汽车,数学,图像)的数据函数.
更新:正如’Eliezer Steinbock’评论说,有必要限制对mongoDB本身的访问.但直到现在我才在路线上做到了.
permissions.js
Cars.allow({ insert: function(userId) { var loggedInUser = Meteor.user() if (loggedInUser && RoleS.UserIsInRole(loggedInUser,['admin','editor'])) return true; },update: function(userId) { var loggedInUser = Meteor.user() if (loggedInUser && RoleS.UserIsInRole(loggedInUser,'editor'])) return true; } });
我的问题
1)我的第一个问题是如何使用角色和组.使用群组的最佳方式是什么?第二个问题是,模块中没有固定的类别.现在我不知道有用的角色/组架构.
2)如何检查角色?因为有不同的角色可以访问:管理员,编辑和专家.此外,我遇到了这些专家的问题,他们只能访问此模块的已定义类别.
3)使permission.js更通用不是更好.我的意思是,是否可以创建一个动态函数,所以我不必在任何地方放置相同的代码?如何以有用的方式在permission.js中实现角色?
App = App || {}; // We are using Namespaces,so you don't have to.. but it's good App.permissions = { insert: function(userId) { var loggedInUser = Meteor.user() if (loggedInUser && RoleS.UserIsInRole(loggedInUser,'editor'])) return true; } }
然后你可以将它用于你的收藏:
Cars.allow(App.permissions); // Or Cars.allow(App.permissions.getPermissionsForGroup('cars'))
在某处定义角色..
角色
// Give user the role "editor" in "cars" group Roles.addUsersToRoles(someUserId,['editor'],'cars'); Roles.addUsersToRoles(someOtherId,['admin'],'cars');
你可以在permissions.js中准备这样的:
权限
App = App || {}; App.permissions = { insert: function(userId) {...},update: function(userId) {...},getPermissionsForGroup: function(group) { return { insert: function(userId,doC) { // Only admin can insert return RoleS.UserIsInRole(userId,"admin",group); },update: function(userId,doc,fields,modifier) { // Editor & Admin can edit return RoleS.UserIsInRole(userId,["editor","admin"],remove: function(userId,doC) { // Only admin can remove return RoleS.UserIsInRole(userId,group); } } }
在此示例中,管理员可以插入和更新..并且编辑者只能更新,但插入.
关于alAnning的文档:您定义的角色和使用这样的角色:
// Super Admin definition.. Roles.addUsersToRoles(superAdminId,Roles.GLOBAL_GROUp); Roles.addUsersToRoles(joesUserId,['manage-team','schedule-game'],'manchester-united.com') Roles.addUsersToRoles(joesUserId,['player','goalie'],'real-madrid.com') RoleS.UserIsInRole(joesUserId,'manage-team','manchester-united.com') // => true RoleS.UserIsInRole(joesUserId,'real-madrid.com') // => false
是的,请确保在收集定义之前包含权限逻辑..显然:)
以上是大佬教程为你收集整理的javascript – 带有alanning:meteorning app的meteor-app中的结构角色管理全部内容,希望文章能够帮你解决javascript – 带有alanning:meteorning app的meteor-app中的结构角色管理所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。