Access.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. MWF.xApplication.Forum.IS_LOGIN = false;
  2. MWF.xApplication.Forum.ForumSetting = null;
  3. MWF.xApplication.Forum.RoleInfoList = [];
  4. MWF.xApplication.Forum.PermissionInfoList = [];
  5. MWF.xApplication.Forum.isBBSSystemAdmin = false;
  6. MWF.xApplication.Forum.Access = new Class({
  7. //SECTION_SUBJECT_MANAGEMENT_ 主题管理
  8. //SECTION_REPLY_MANAGEMENT_ 回帖管理
  9. //SECTION_SECTION_MANAGER_ 子板块增删改
  10. //SECTION_PERMISSION_MANAGEMENT_ 权限管理
  11. //SECTION_CONFIG_MANAGEMENT_ 参数配置
  12. //"SECTION_GUEST_"; //查看范围
  13. //"SECTION_SUBJECT_PUBLISHER_"; //发帖范围
  14. //"SECTION_SUBJECT_AUDITOR_"; //发帖审核
  15. //"SECTION_REPLY_PUBLISHER_"; //回复范围
  16. //"SECTION_REPLY_AUDITOR_"; //回复审核
  17. //"SECTION_RECOMMENDER_"; //推荐
  18. //"SECTION_SUBJECT_STICK_"; //置顶
  19. //"SECTION_SUBJECT_CREAM_"; //精华
  20. initialize: function ( actions, lp, userName ) {
  21. this.actions = actions;
  22. this.lp = lp;
  23. this.userName = userName || layout.desktop.session.user.distinguishedName || "";
  24. this.anonymous = layout.desktop.session.user.name == "anonymous";
  25. if( this.anonymous ){
  26. MWF.Actions.get("x_organization_assemble_personal").getRegisterMode(function(json){
  27. this.signUpMode = json.data.value
  28. }.bind(this), null ,false)
  29. }
  30. if( !MWF.xApplication.Forum.ForumSetting ){
  31. MWF.xApplication.Forum.ForumSetting = {};
  32. this.actions.listCategoryAll(function (json) {
  33. if( !json.data )json.data = [];
  34. json.data.each(function (d) {
  35. MWF.xApplication.Forum.ForumSetting[d.id] = d;
  36. }.bind(this))
  37. }.bind(this))
  38. }
  39. },
  40. login : function( callback ){
  41. if( !MWF.xApplication.Forum.IS_LOGIN ){
  42. this.actions.login( {}, function( json ){
  43. MWF.xApplication.Forum.RoleInfoList = json.data ? json.data.roleInfoList : [];
  44. MWF.xApplication.Forum.PermissionInfoList = json.data ? json.data.permissionInfoList : [];
  45. MWF.xApplication.Forum.IS_LOGIN = true;
  46. MWF.xApplication.Forum.isBBSSystemAdmin = json.data ? json.data.isBBSSystemAdmin : false;
  47. if( callback )callback();
  48. }.bind(this))
  49. }else{
  50. if( callback )callback();
  51. }
  52. },
  53. isAnonymous : function(){
  54. return this.anonymous;
  55. },
  56. isAnonymousDynamic : function(){
  57. var flag = true;
  58. MWF.Actions.get("x_organization_assemble_authentication").authentication( function( json ){
  59. if (json.data.tokenType == "anonymous"){
  60. this.userName = layout.desktop.session.user.distinguishedName = "anonymous";
  61. flag = true;
  62. }else{
  63. this.userName = layout.desktop.session.user.distinguishedName = json.data.distinguishedName;
  64. flag = false;
  65. }
  66. }.bind(this), null, false );
  67. return flag;
  68. },
  69. isAdmin : function(){
  70. return MWF.AC.isBBSManager() || MWF.xApplication.Forum.isBBSSystemAdmin; //(layout.desktop.session.user.roleList.indexOf("BBSSystemAdmin")!=-1);
  71. },
  72. inArray : function( managers, callback, username ){
  73. var flag = false;
  74. if( typeOf(managers) == "string" )managers = managers.split(",");
  75. if( managers.indexOf( username || this.userName ) != -1 )flag = true;
  76. if( callback )callback( flag );
  77. return flag;
  78. },
  79. isForumViewer : function( forumIdOrData ){
  80. var flag = true;
  81. if( this.hasForumAdminAuthority( forumIdOrData, null, null, false ) ){
  82. return true;
  83. }
  84. this.getCategoryData( forumIdOrData, function( data ){
  85. if( data.forumVisible != this.lp.allPerson ){
  86. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "FORUM_GUEST_" + data.id ) == -1 ){
  87. flag = false
  88. }
  89. }
  90. });
  91. return flag;
  92. },
  93. isSectionViewer : function( sectionIdOrData ){
  94. var flag = true;
  95. if( this.hasSectionAdminAuthority( sectionIdOrData, null, null, false ) ){
  96. return true;
  97. }
  98. if( typeOf( sectionIdOrData ) == "string" ){
  99. this.actions.getSection( sectionIdOrData, function( json ){
  100. var data = json.data;
  101. if( data.sectionVisible != this.lp.allPerson ){
  102. if( MWF.xApplication.Forum.PermissionInfoList.indexOf( "SECTION_VIEW_" + data.id ) == -1 ){
  103. flag = false
  104. }
  105. }
  106. }.bind(this), null, async)
  107. }else{
  108. var data = sectionIdOrData;
  109. if( data.sectionVisible != this.lp.allPerson ){
  110. if( MWF.xApplication.Forum.PermissionInfoList.indexOf( "SECTION_VIEW_" + data.id ) == -1 ){
  111. flag = false
  112. }
  113. }
  114. }
  115. return flag;
  116. },
  117. isRecommender : function( sectionIdOrData ){
  118. var flag = false;
  119. if( typeOf( sectionIdOrData ) == "string" ){
  120. this.actions.getSection( sectionIdOrData, function( json ){
  121. var data = json.data;
  122. //if( data.sectionVisible == this.lp.allPerson && data.indexRecommendable == true ){
  123. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_RECOMMENDER_" + data.id ) != -1 ){
  124. flag = true
  125. }else if( this.hasSectionAdminAuthority( data, null, null, false ) ){ //如果是管理员
  126. flag = true;
  127. }
  128. //}
  129. }.bind(this), null, async)
  130. }else{
  131. var data = sectionIdOrData;
  132. //if( data.sectionVisible == this.lp.allPerson && data.indexRecommendable == true ){
  133. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_RECOMMENDER_" + data.id ) != -1 ){
  134. flag = true
  135. }else if( this.hasSectionAdminAuthority( data, null, null, false ) ){ //如果是管理员
  136. flag = true;
  137. }
  138. //}
  139. }
  140. return flag;
  141. },
  142. isSubjectPublisher : function( sectionIdOrData ){
  143. var flag = true;
  144. if( this.hasSectionAdminAuthority( sectionIdOrData, null, null, false ) ){
  145. return true;
  146. }
  147. if( typeOf( sectionIdOrData ) == "string" ){
  148. this.actions.getSection( sectionIdOrData, function( json ){
  149. var data = json.data;
  150. if( data.subjectPublishAble != this.lp.allPerson ){
  151. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_SUBJECT_PUBLISHER_" + data.id ) == -1 ){
  152. flag = false
  153. }
  154. }
  155. }.bind(this), null, async)
  156. }else{
  157. var data = sectionIdOrData;
  158. if( data.subjectPublishAble != this.lp.allPerson ){
  159. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_SUBJECT_PUBLISHER_" + data.id ) == -1 ){
  160. flag = false
  161. }
  162. }
  163. }
  164. return flag;
  165. },
  166. isReplyPublisher : function( sectionIdOrData ){
  167. var flag = true;
  168. if( this.hasSectionAdminAuthority( sectionIdOrData, null, null, false ) ){
  169. return true;
  170. }
  171. if( typeOf( sectionIdOrData ) == "string" ){
  172. this.actions.getSection( sectionIdOrData, function( json ){
  173. var data = json.data;
  174. if( data.replyPublishAble != this.lp.allPerson ){
  175. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_REPLY_PUBLISHER_" + data.id ) == -1 ){
  176. flag = false
  177. }
  178. }
  179. }.bind(this), null, false)
  180. }else{
  181. var data = sectionIdOrData;
  182. if( data.replyPublishAble != this.lp.allPerson ){
  183. if( MWF.xApplication.Forum.RoleInfoList.indexOf( "SECTION_REPLY_PUBLISHER_" + data.id ) == -1 ){
  184. flag = false
  185. }
  186. }
  187. }
  188. return flag;
  189. },
  190. getCategoryData : function( forumIdOrData , callback ){
  191. if( typeOf( forumIdOrData ) == "string" ){
  192. if( MWF.xApplication.Forum.ForumSetting[ forumIdOrData ] ){
  193. if( callback )callback( MWF.xApplication.Forum.ForumSetting[ forumIdOrData ] );
  194. }else{
  195. this.actions.getCategory( forumIdOrData, function( json ){
  196. MWF.xApplication.Forum.ForumSetting[ forumIdOrData ] = json.data;
  197. if( callback )callback( json.data );
  198. }.bind(this), null, false )
  199. }
  200. }else{
  201. if( !MWF.xApplication.Forum.ForumSetting[ forumIdOrData.id ] ){
  202. MWF.xApplication.Forum.ForumSetting[ forumIdOrData ] = forumIdOrData;
  203. }
  204. if( callback )callback( forumIdOrData );
  205. }
  206. },
  207. isForumManager : function( forumIdOrData, callback, username, async ){ //是否分区管理员
  208. var flag = false;
  209. this.getCategoryData( forumIdOrData, function( forumData ){
  210. flag = this.inArray( forumData.forumManagerName , callback, username );
  211. }.bind(this) );
  212. return flag;
  213. },
  214. isSectionManager : function( sectionIdOrData , callback, username , async){ //是否板块管理员
  215. var flag = false;
  216. if( typeOf( sectionIdOrData ) == "string" ){
  217. this.actions.getSection( sectionIdOrData, function( json ){
  218. flag = this.inArray( json.data.moderatorNames, callback, username );
  219. }.bind(this), null, async)
  220. }else{
  221. flag = this.inArray( sectionIdOrData.moderatorNames , callback, username );
  222. }
  223. return flag;
  224. },
  225. hasForumAdminAuthority : function( forumIdOrData, callback, username, async ) { //具有分区管理权限
  226. if (!username && this.isAdmin()){
  227. if( callback )callback( true );
  228. return true;
  229. }
  230. var flag = false;
  231. flag = this.isForumManager( forumIdOrData, function( flag ){
  232. if( callback )callback( flag );
  233. }.bind(this), username , async);
  234. return flag;
  235. },
  236. hasSectionAdminAuthority : function( sectionIdOrData , callback, username, async ){ //具有板块管理权限
  237. if (!username && this.isAdmin()) {
  238. if (callback)callback(true);
  239. return true;
  240. }
  241. var flag = false;
  242. var fun = function( data ){
  243. var managers = data.moderatorNames;
  244. if( typeOf(managers) == "string" )managers = managers.split(",");
  245. if( managers.indexOf( username || this.userName ) != -1 )flag = true;
  246. if( flag ){
  247. if( callback )callback( flag );
  248. }else{
  249. flag = this.isForumManager( data.forumId, function( flag ){
  250. if( callback )callback( flag );
  251. }.bind(this), username , async)
  252. }
  253. }.bind(this);
  254. if( typeOf( sectionIdOrData ) == "string" ){
  255. this.actions.getSection( sectionIdOrData, function( json ){
  256. fun( json.data );
  257. }.bind(this), null, async)
  258. }else{
  259. fun( sectionIdOrData );
  260. }
  261. return flag;
  262. },
  263. getUserPermission: function (callback, reload) {
  264. if( !reload && this.userPermission ){
  265. callback(this.userPermission);
  266. return;
  267. }
  268. o2.Actions.load("x_bbs_assemble_control").PermissionInfoAction.getUserPermission(function (json) {
  269. this.userPermission = json.data;
  270. callback(this.userPermission);
  271. }.bind(this))
  272. }
  273. });