Access.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xApplication = MWF.xApplication || {};
  3. //MWF.xDesktop.requireApp("Organization", "Actions.RestActions", null, false);
  4. MWF.xDesktop.Access = MWF.AC = {
  5. "companyList": null,
  6. "action": null,
  7. getRoleList: function(){
  8. if (!this.roleList){
  9. this.roleList = [];
  10. layout.desktop.session.user.roleList.each(function(role){
  11. this.roleList.push(role.substring(0, role.indexOf("@")).toLowerCase());
  12. }.bind(this));
  13. }
  14. },
  15. isAdministrator: function(){
  16. this.getRoleList();
  17. return (layout.desktop.session.user.name.toLowerCase() === "xadmin") || (this.roleList.indexOf("manager")!==-1) || (this.roleList.indexOf("systemmanager")!==-1);
  18. },
  19. isManager: function(){
  20. this.getRoleList();
  21. return (layout.desktop.session.user.name.toLowerCase() === "xadmin") || (this.roleList.indexOf("manager")!==-1);
  22. },
  23. isProcessManager: function(){
  24. if (!layout.desktop.session.user.roleList) return false;
  25. this.getRoleList();
  26. return this.isAdministrator() || (this.roleList.indexOf("processplatformmanager")!==-1);
  27. },
  28. isPortalManager: function(){
  29. if (!layout.desktop.session.user.roleList) return false;
  30. this.getRoleList();
  31. return this.isAdministrator() || (this.roleList.indexOf("portalmanager")!==-1);
  32. },
  33. isPortalCreator: function(){
  34. if (!layout.desktop.session.user.roleList) return false;
  35. this.getRoleList();
  36. return this.isAdministrator() || (this.roleList.indexOf("portalmanager")!==-1) || (this.roleList.indexOf("portalcreator")!==-1);
  37. },
  38. isQueryManager: function(){
  39. if (!layout.desktop.session.user.roleList) return false;
  40. this.getRoleList();
  41. return this.isAdministrator() || (this.roleList.indexOf("querymanager")!==-1);
  42. },
  43. isQueryCreator: function(){
  44. if (!layout.desktop.session.user.roleList) return false;
  45. this.getRoleList();
  46. return this.isAdministrator() || (this.roleList.indexOf("querymanager")!==-1) || (this.roleList.indexOf("querycreator")!==-1);
  47. },
  48. isOrganizationManager: function(){
  49. if (!layout.desktop.session.user.roleList) return false;
  50. this.getRoleList();
  51. return this.isAdministrator() || (this.roleList.indexOf("organizationmanager")!==-1);
  52. },
  53. isMessageManager: function(){
  54. if (!layout.desktop.session.user.roleList) return false;
  55. this.getRoleList();
  56. return this.isAdministrator() || (this.roleList.indexOf("messagemanager")!==-1);
  57. },
  58. isServiceManager: function(){
  59. if (!layout.desktop.session.user.roleList) return false;
  60. this.getRoleList();
  61. return this.isAdministrator() || (this.roleList.indexOf("servicemanager")!==-1);
  62. },
  63. isUnitManager: function(){
  64. if (!layout.desktop.session.user.roleList) return false;
  65. this.getRoleList();
  66. return this.isAdministrator() || (this.roleList.indexOf("unitmanager")!==-1);
  67. },
  68. isGroupManager: function(){
  69. if (!layout.desktop.session.user.roleList) return false;
  70. this.getRoleList();
  71. return this.isAdministrator() || (this.roleList.indexOf("groupmanager")!==-1);
  72. },
  73. isRoleManager: function(){
  74. if (!layout.desktop.session.user.roleList) return false;
  75. this.getRoleList();
  76. return this.isAdministrator() || (this.roleList.indexOf("rolemanager")!==-1);
  77. },
  78. isPersonManager: function(){
  79. if (!layout.desktop.session.user.roleList) return false;
  80. this.getRoleList();
  81. return this.isAdministrator() || (this.roleList.indexOf("personmanager")!==-1);
  82. },
  83. isSystemManager: function(){
  84. if (!layout.desktop.session.user.roleList) return false;
  85. this.getRoleList();
  86. return (this.roleList.indexOf("systemmanager")!==-1);
  87. },
  88. isSecurityManager: function(){
  89. if (!layout.desktop.session.user.roleList) return false;
  90. this.getRoleList();
  91. return (this.roleList.indexOf("securitymanager")!==-1);
  92. },
  93. isAuditManager: function(){
  94. if (!layout.desktop.session.user.roleList) return false;
  95. this.getRoleList();
  96. return (this.roleList.indexOf("auditmanager")!==-1);
  97. },
  98. isGroupCreator: function(){
  99. if (!layout.desktop.session.user.roleList) return false;
  100. this.getRoleList();
  101. return (this.roleList.indexOf("groupcreator")!==-1);
  102. },
  103. isProcessPlatformCreator: function(){
  104. if (this.isAdministrator()) return true;
  105. if (this.isProcessManager()) return true;
  106. if (!layout.desktop.session.user.roleList) return false;
  107. this.getRoleList();
  108. return (this.roleList.indexOf("processplatformcreator")!==-1);
  109. },
  110. isPortalPlatformCreator: function(){
  111. if (this.isAdministrator()) return true;
  112. if (this.isPortalCreator()) return true;
  113. if (!layout.desktop.session.user.roleList) return false;
  114. this.getRoleList();
  115. return (this.roleList.indexOf("portalcreator")!==-1);
  116. },
  117. isQueryPlatformCreator: function(){
  118. if (this.isAdministrator()) return true;
  119. if (this.isQueryCreator()) return true;
  120. if (!layout.desktop.session.user.roleList) return false;
  121. this.getRoleList();
  122. return (this.roleList.indexOf("querycreator")!==-1);
  123. },
  124. isApplicationManager: function(option){
  125. if (this.isAdministrator()) {
  126. if (option.yes) option.yes();
  127. }else{
  128. }
  129. },
  130. isCMSManager: function(){
  131. this.getRoleList();
  132. return this.isAdministrator() || (this.roleList.indexOf("cmsmanager")!==-1);
  133. },
  134. isCMSCreator: function(){
  135. this.getRoleList();
  136. return this.isAdministrator() || (this.roleList.indexOf("cmsmanager")!==-1) || (this.roleList.indexOf("cmscreator")!==-1);
  137. },
  138. isBBSManager: function(){
  139. this.getRoleList();
  140. return this.isAdministrator() || (this.roleList.indexOf("bbsmanager")!==-1) || (this.roleList.indexOf("bssmanager")!==-1);
  141. },
  142. isOKRManager: function(){
  143. this.getRoleList();
  144. return this.isAdministrator() || (this.roleList.indexOf("okrmanager")!==-1);
  145. },
  146. isCRMManager: function(){
  147. this.getRoleList();
  148. return this.isAdministrator() || (this.roleList.indexOf("crmmanager")!==-1);
  149. },
  150. isAttendanceManager: function(){
  151. this.getRoleList();
  152. return this.isAdministrator() || (this.roleList.indexOf("attendancemanager")!==-1);
  153. },
  154. isMeetingAdministrator: function(){
  155. this.getRoleList();
  156. return this.isAdministrator() || (this.roleList.indexOf("meetingmanager")!==-1);
  157. },
  158. isHotPictureManager: function(){
  159. this.getRoleList();
  160. return this.isAdministrator() || (this.roleList.indexOf("hotpicturemanager")!==-1);
  161. },
  162. isPersonEditor: function(option){
  163. //{list: "idlist", "yes": trueFunction, "no": falseFunction}
  164. if (this.isAdministrator()) return true;
  165. if (this.isPersonManager()) return true;
  166. if (option.list && option.list.length){
  167. if (option.list.indexOf(layout.desktop.session.user.id)!==-1) return true;
  168. }
  169. return false;
  170. },
  171. isCompanyEditor: function(option) {
  172. //{id: "companyId", "yes": trueFunction, "no": falseFunction}
  173. if (this.isAdministrator()){
  174. if (option.yes) option.yes();
  175. }else if (this.isCompanyCreator()){
  176. if (option.yes) option.yes();
  177. }else{
  178. this.getCompanyList(function(){
  179. if (option.id){
  180. if (this.companyList.indexOf(option.id)!==-1){
  181. if (option.yes) option.yes();
  182. }else{
  183. if (option.no) option.no();
  184. }
  185. }else{
  186. if (this.companyList.length>0){
  187. if (option.yes) option.yes();
  188. }else{
  189. if (option.no) option.no();
  190. }
  191. }
  192. }.bind(this));
  193. }
  194. },
  195. isDepartmentEditor: function(option) {
  196. //{id: "superCompanyId", "yes": trueFunction, "no": falseFunction}
  197. if (this.isAdministrator()){
  198. if (option.yes) option.yes();
  199. }else if (this.isCompanyCreator()){
  200. if (option.yes) option.yes();
  201. }else{
  202. this.getCompanyList(function(){
  203. if (option.id){
  204. if (this.companyList.indexOf(option.id)!==-1){
  205. if (option.yes) option.yes();
  206. }else{
  207. if (option.no) option.no();
  208. }
  209. }else{
  210. if (option.no) option.no();
  211. }
  212. }.bind(this));
  213. }
  214. },
  215. getCompanyList: function(callback){
  216. if (this.companyList===null){
  217. this.getAction();
  218. this.action.getCompanyAccess(function(json){
  219. if (json.data){
  220. this.companyList = json.data;
  221. }else{
  222. this.companyList = [];
  223. }
  224. if (callback) callback();
  225. }.bind(this), null, layout.desktop.session.user.id);
  226. }else{
  227. if (callback) callback();
  228. }
  229. },
  230. getAction: function(){
  231. if (!this.action) this.action = MWF.Actions.get("x_organization_assemble_control");
  232. //if (!this.action) this.action = new MWF.xApplication.Organization.Actions.RestActions();
  233. }
  234. }