Browse Source

新增权限功能验证

hejq 8 years ago
parent
commit
5204fcfbd7

+ 12 - 3
src/main/java/com/uas/platform/b2b/dao/RoleDao.java

@@ -1,13 +1,12 @@
 package com.uas.platform.b2b.dao;
 
-import java.util.List;
-
+import com.uas.platform.b2b.model.Role;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
-import com.uas.platform.b2b.model.Role;
+import java.util.List;
 
 @Repository
 public interface RoleDao extends JpaRepository<Role, Long> {
@@ -44,4 +43,14 @@ public interface RoleDao extends JpaRepository<Role, Long> {
 	public int getCountByEnUUAndDesc(@Param("enUU") long enUU, @Param("desc") String desc);
 
     List<Role> findByEnUUAndIssys(Long vendUU, short yes);
+
+	/**
+	 * 查询当前用户在当前企业的角色是否是管理员或者销售经理
+	 *
+	 * @param enuu
+	 * @param useruu
+	 * @return
+	 */
+    @Query(value = "select count(1) from sec$roles r left join sec$userrole u on r.role_id = u.role_id where r.role_enuu = :enuu and u.user_uu = :useruu and (r.role_name = 'ROLE_ADMIN' or r.role_name = 'ROLE_SALEMANAGER')",nativeQuery = true)
+    Double findByEnuuAndUseruu(@Param("enuu") Long enuu, @Param("useruu") Long useruu);
 }

+ 10 - 2
src/main/java/com/uas/platform/b2b/service/RoleService.java

@@ -1,8 +1,9 @@
 package com.uas.platform.b2b.service;
 
-import java.util.List;
-
 import com.uas.platform.b2b.model.Role;
+import org.springframework.ui.ModelMap;
+
+import java.util.List;
 
 public interface RoleService {
 
@@ -50,4 +51,11 @@ public interface RoleService {
 	 */
 	public void delete(long id);
 
+	/**
+	 * 查询当前用户在当前企业的角色是否是管理员或者销售经理
+	 *
+	 * @return
+	 */
+	public ModelMap getCurrentRoles();
+
 }

+ 6 - 0
src/main/java/com/uas/platform/b2b/service/impl/RoleServiceImpl.java

@@ -11,6 +11,7 @@ import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.Constant;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
 import org.springframework.util.Assert;
 import org.springframework.util.CollectionUtils;
 
@@ -86,4 +87,9 @@ public class RoleServiceImpl implements RoleService {
 		delete(findById(id));
 	}
 
+	@Override
+	public ModelMap getCurrentRoles() {
+		return new ModelMap("count", roleDao.findByEnuuAndUseruu(SystemSession.getUser().getEnterprise().getUu(),SystemSession.getUser().getUserUU()));
+	}
+
 }

+ 10 - 3
src/main/webapp/resources/js/index/app.js

@@ -1825,12 +1825,18 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
     }]);
 
     // 客户
-    app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser) {
+    app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
         BaseService.scrollBackToTop();
         $scope.userInfoResult = true;
         AuthenticationService.getAuthentication().success(function (data) {
             $scope.loading = false;
             $scope.thisUser = data;
+        });
+        // 获取当前用户分配客户的操作权限
+        CurrentRole.roles({}, function (data) {
+            $scope.enabled =  data.count > 0 ? true : false ;
+        }, function (response) {
+
         });
         var getCustInfos = function (custuu) {
             if (custuu) {
@@ -1874,8 +1880,8 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
             AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
                 customer.enTransfer = data.result;
                 //是管理员,或者被转移了权限时
-                console.log(customer.enTransfer);
-                if ($scope.thisUser.sys || customer.enTransfer) {
+                console.log($scope.thisUser);
+                if ($scope.enabled || customer.enTransfer) {
                     var modalInstance = $modal.open({
                         animation: true,
                         templateUrl: 'static/tpl/index/account/add_userInfo.html',
@@ -13511,6 +13517,7 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         // 分配权限
         $scope.addUserInfo = function (customer) {
             //TODO
+            console.log($scope.thisUser);
             if ($scope.thisUser.sys) {
                 var modalInstance = $modal.open({
                     animation: true,

+ 9 - 1
src/main/webapp/resources/js/index/services/Account.js

@@ -39,5 +39,13 @@ define([ 'ngResource' ], function() {
 				method: 'GET'
 			}
 		})
-	}]);
+	}]).factory('CurrentRole', ['$resource', function($resource) {
+        return $resource('account/role', {}, {
+            //当前企业对应的角色
+            roles: {
+                url: 'account/role/currentRole',
+                method: 'GET'
+            }
+        })
+    }]);
 });

+ 1 - 1
src/main/webapp/resources/tpl/index/approvalFlow/user.html

@@ -455,7 +455,7 @@
 						</td>
 						<!-- 系统管理员无法被编辑限制,因为用户反馈注册用户都是业务员,需要权限来保护隐私,所以拿掉这个限制 -->
 						<!-- ng-show="user.sys && enterprise.enAdminuu != u.userUU" -->
-						<td class="row-operator" >
+						<td class="row-operator" ng-show="user.sys && enterprise.enAdminuu != u.userUU">
 							<a class="operator-trigger" href="javascript:void(0);"><i class="fa fa-pencil fa-lg" ng-show="(user.sys && enterprise.enAdminuu != u.userUU) || $data.length == 1"></i></a>
 							<ul class="list-unstyle list-inline operator-menu" ng-show="(user.sys && enterprise.enAdminuu != u.userUU) || $data.length == 1">
 								<li><a ng-click="editUserRole(u)"><i class="fa fa-fw fa-pencil-square-o" style="color: #fff"></i>编辑</a></li>