您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. wn.provide("wn.perm");
  23. var READ = 0, WRITE = 1, CREATE = 2;
  24. var SUBMIT = 3, CANCEL = 4, AMEND = 5;
  25. $.extend(wn.perm, {
  26. doctype_perm: {},
  27. has_perm: function(doctype, level, type) {
  28. if(!level) level = 0;
  29. var perms = wn.perm.doctype_perm;
  30. if(!perms[doctype])
  31. perms[doctype] = wn.perm.get_perm(doctype);
  32. if(!perms[doctype])
  33. return false;
  34. if(!perms[doctype][level])
  35. return false;
  36. return perms[doctype][level][type];
  37. },
  38. get_perm: function(doctype, dn, ignore_submit) {
  39. var perm = [[0,0],];
  40. if(in_list(user_roles, 'Administrator'))
  41. perm[0][READ] = 1;
  42. $.each(wn.model.get("DocPerm", {parent:doctype}), function(i, p) {
  43. var pl = cint(p.permlevel?p.permlevel:0);
  44. // if user role
  45. if(in_list(user_roles, p.role)) {
  46. // if field match
  47. if(wn.perm.check_match(p, doctype, dn)) { // new style
  48. if(!perm[pl])
  49. perm[pl] = [];
  50. if(!perm[pl][READ]) {
  51. if(cint(p.read)) perm[pl][READ]=1; else perm[pl][READ]=0;
  52. }
  53. if(!perm[pl][WRITE]) {
  54. if(cint(p.write)) { perm[pl][WRITE]=1; perm[pl][READ]=1; }
  55. else perm[pl][WRITE]=0;
  56. }
  57. if(!perm[pl][CREATE]) {
  58. if(cint(p.create))perm[pl][CREATE]=1; else perm[pl][CREATE]=0;
  59. }
  60. if(!perm[pl][SUBMIT]) {
  61. if(cint(p.submit))perm[pl][SUBMIT]=1; else perm[pl][SUBMIT]=0;
  62. }
  63. if(!perm[pl][CANCEL]) {
  64. if(cint(p.cancel))perm[pl][CANCEL]=1; else perm[pl][CANCEL]=0;
  65. }
  66. if(!perm[pl][AMEND]) {
  67. if(cint(p.amend)) perm[pl][AMEND]=1; else perm[pl][AMEND]=0;
  68. }
  69. }
  70. }
  71. });
  72. return perm;
  73. },
  74. check_match: function(p, doctype, name) {
  75. if(!name) return true;
  76. var out =false;
  77. if(p.match) {
  78. if(p.match.indexOf(":")!=-1) {
  79. keys = p.match.split(":");
  80. var document_key = keys[0];
  81. var default_key = keys[1];
  82. } else {
  83. var document_key = p.match;
  84. var default_key = p.match;
  85. }
  86. if(user_defaults[default_key]) {
  87. for(var i=0;i<user_defaults[default_key].length;i++) {
  88. // user must have match field in defaults
  89. if(user_defaults[default_key][i]==locals[doctype][name][document_key]) {
  90. // must match document
  91. return true;
  92. }
  93. }
  94. return false;
  95. } else if(!locals[doctype][name][document_key]) { // blanks are true
  96. return true;
  97. } else {
  98. return false;
  99. }
  100. } else {
  101. return true;
  102. }
  103. },
  104. });