give_acl.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from .tool.func import *
  2. def give_acl_2(conn, name):
  3. curs = conn.cursor()
  4. check_ok = ''
  5. if flask.request.method == 'POST':
  6. check_data = 'acl (' + name + ')'
  7. else:
  8. check_data = None
  9. user_data = re.search('^user:(.+)$', name)
  10. if user_data:
  11. if check_data and custom()[2] == 0:
  12. return redirect('/login')
  13. if user_data.groups()[0] != ip_check():
  14. if admin_check(5, check_data) != 1:
  15. if check_data:
  16. return re_error('/error/3')
  17. else:
  18. check_ok = 'disabled'
  19. else:
  20. if admin_check(5, check_data) != 1:
  21. if check_data:
  22. return re_error('/error/3')
  23. else:
  24. check_ok = 'disabled'
  25. if flask.request.method == 'POST':
  26. decu = flask.request.form.get('decu', '')
  27. view = flask.request.form.get('view', '')
  28. curs.execute("select title from acl where title = ?", [name])
  29. if curs.fetchall():
  30. curs.execute("update acl set decu = ? where title = ?", [decu, name])
  31. curs.execute("update acl set dis = ? where title = ?", [flask.request.form.get('dis', ''), name])
  32. curs.execute("update acl set why = ? where title = ?", [flask.request.form.get('why', ''), name])
  33. curs.execute("update acl set view = ? where title = ?", [view, name])
  34. else:
  35. curs.execute("insert into acl (title, decu, dis, why, view) values (?, ?, ?, ?, ?)", [
  36. name,
  37. decu,
  38. flask.request.form.get('dis', ''),
  39. flask.request.form.get('why', ''),
  40. view
  41. ])
  42. curs.execute("select title from acl where title = ? and decu = '' and dis = '' and view = ''", [name])
  43. if curs.fetchall():
  44. curs.execute("delete from acl where title = ?", [name])
  45. conn.commit()
  46. return redirect('/acl/' + url_pas(name))
  47. else:
  48. data = '<h2>' + load_lang('document_acl') + '</h2><hr class=\"main_hr\"><select name="decu" ' + check_ok + '>'
  49. if re.search('^user:', name):
  50. acl_list = [['', 'normal'], ['user', 'member'], ['all', 'all']]
  51. else:
  52. acl_list = [['', 'normal'], ['user', 'member'], ['admin', 'admin'], ['50_edit', '50 edit'], ['email', 'email']]
  53. curs.execute("select decu from acl where title = ?", [name])
  54. acl_data = curs.fetchall()
  55. for data_list in acl_list:
  56. if acl_data and acl_data[0][0] == data_list[0]:
  57. check = 'selected="selected"'
  58. else:
  59. check = ''
  60. data += '<option value="' + data_list[0] + '" ' + check + '>' + data_list[1] + '</option>'
  61. data += '</select>'
  62. if not re.search('^user:', name):
  63. data += '<hr class=\"main_hr\"><h2>' + load_lang('discussion_acl') + '</h2><hr class=\"main_hr\"><select name="dis" ' + check_ok + '>'
  64. curs.execute("select dis, why, view from acl where title = ?", [name])
  65. acl_data = curs.fetchall()
  66. for data_list in acl_list:
  67. if acl_data and acl_data[0][0] == data_list[0]:
  68. check = 'selected="selected"'
  69. else:
  70. check = ''
  71. data += '<option value="' + data_list[0] + '" ' + check + '>' + data_list[1] + '</option>'
  72. data += '</select>'
  73. data += '<hr class=\"main_hr\"><h2>' + load_lang('view_acl') + '</h2><hr class=\"main_hr\"><select name="view" ' + check_ok + '>'
  74. for data_list in acl_list:
  75. if acl_data and acl_data[0][2] == data_list[0]:
  76. check = 'selected="selected"'
  77. else:
  78. check = ''
  79. data += '<option value="' + data_list[0] + '" ' + check + '>' + data_list[1] + '</option>'
  80. data += '''
  81. </select>
  82. <h2>''' + load_lang('explanation') + '''</h2>
  83. <ul>
  84. <li>normal : ''' + load_lang('default') + '''</li>
  85. <li>admin : ''' + load_lang('admin_acl') + '''</li>
  86. <li>member : ''' + load_lang('member_acl') + '''</li>
  87. <li>50 edit : ''' + load_lang('50_edit_acl') + '''</li>
  88. <li>all : ''' + load_lang('all_acl') + '''</li>
  89. <li>email : ''' + load_lang('email_acl') + '''</li>
  90. </ul>
  91. '''
  92. if check_ok == '':
  93. if acl_data:
  94. data += '<hr class=\"main_hr\"><input value="' + html.escape(acl_data[0][1]) + '" placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>'
  95. else:
  96. data += '<hr class=\"main_hr\"><input placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>'
  97. return easy_minify(flask.render_template(skin_check(),
  98. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('acl') + ')', 0])],
  99. data = '''
  100. <form method="post">
  101. ''' + data + '''
  102. <hr class=\"main_hr\">
  103. <button type="submit" ''' + check_ok + '''>''' + load_lang('save') + '''</button>
  104. </form>
  105. ''',
  106. menu = [['w/' + url_pas(name), load_lang('document')], ['manager', load_lang('admin')]]
  107. ))