give_admin_groups.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from .tool.func import *
  2. def give_admin_groups(name = 'test'):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. acl_name_list = [
  6. [1, 'owner', get_lang(conn, 'owner_authority')],
  7. [2, '', get_lang(conn, 'all_function_authority')],
  8. [2, 'admin', get_lang(conn, 'admin_authority')],
  9. [3, 'ban', get_lang(conn, 'ban_authority')],
  10. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  11. [3, 'toron', get_lang(conn, 'discussion_authority')],
  12. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  13. [3, 'check', get_lang(conn, 'user_analyze_authority')],
  14. [4, 'view_user_watchlist', get_lang(conn, 'view_user_watchlist_authority')],
  15. [4, '', get_lang(conn, 'user_check_authority')],
  16. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  17. [3, 'acl', get_lang(conn, 'document_acl_authority')],
  18. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  19. [3, 'hidel', get_lang(conn, 'history_hide_authority')],
  20. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  21. [3, 'give', get_lang(conn, 'authorization_authority')],
  22. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  23. [3, 'bbs', get_lang(conn, 'bbs_authority')],
  24. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  25. [3, 'vote', get_lang(conn, 'vote_authority')],
  26. [4, '', get_lang(conn, 'admin_default_feature_authority')],
  27. [3, 'admin_default_feature', get_lang(conn, 'admin_default_feature_authority')],
  28. [4, 'doc_watch_list_view', get_lang(conn, 'doc_watch_list_view_authority')],
  29. [4, 'treat_as_admin', get_lang(conn, 'treat_as_admin_authority')],
  30. [4, 'view_hide_user_name', get_lang(conn, 'view_hide_user_name_authority')],
  31. [4, 'user_name_bold', get_lang(conn, 'user_name_bold_authority')],
  32. [4, 'multiple_upload', get_lang(conn, 'multiple_upload_authority')],
  33. [4, 'slow_edit_pass', get_lang(conn, 'slow_edit_pass_authority')],
  34. [4, 'edit_bottom_compulsion_pass', get_lang(conn, 'edit_bottom_compulsion_pass_authority')],
  35. [4, '', get_lang(conn, 'user_authority')],
  36. [1, 'user', get_lang(conn, 'user_authority')],
  37. [2, 'captcha_pass', get_lang(conn, 'captcha_pass_authority')],
  38. [2, 'ip', get_lang(conn, 'ip_authority')],
  39. [3, 'document', get_lang(conn, 'document_authority')],
  40. [4, 'edit', get_lang(conn, 'edit_authority')],
  41. [5, '', get_lang(conn, 'view_authority')],
  42. [4, 'edit_request', get_lang(conn, 'edit_request_authority')],
  43. [5, '', get_lang(conn, 'view_authority')],
  44. [4, 'move', get_lang(conn, 'move_authority')],
  45. [5, '', get_lang(conn, 'view_authority')],
  46. [4, 'new_make', get_lang(conn, 'new_make_authority')],
  47. [5, '', get_lang(conn, 'view_authority')],
  48. [4, 'delete', get_lang(conn, 'delete_authority')],
  49. [5, '', get_lang(conn, 'view_authority')],
  50. [4, 'view', get_lang(conn, 'view_authority')],
  51. [3, 'discuss', get_lang(conn, 'discuss_authority')],
  52. [4, 'discuss_view', get_lang(conn, 'discuss_authority')],
  53. [3, 'upload', get_lang(conn, 'upload_authority')],
  54. [3, 'vote', get_lang(conn, 'vote_authority')],
  55. [3, 'bbs_use', get_lang(conn, 'bbs_authority')],
  56. [4, 'bbs_edit', get_lang(conn, 'bbs_edit_authority')],
  57. [5, '', get_lang(conn, 'bbs_view_authority')],
  58. [4, 'bbs_comment', get_lang(conn, 'bbs_comment_authority')],
  59. [5, '', get_lang(conn, 'bbs_view_authority')],
  60. [4, 'bbs_view', get_lang(conn, 'bbs_view_authority')],
  61. [3, 'captcha_one_check_five_pass', get_lang(conn, 'captcha_one_check_five_pass_authority')]
  62. ]
  63. if flask.request.method == 'POST':
  64. if acl_check(tool = 'owner_auth', memo = 'auth list add (' + name + ')') == 1:
  65. return re_error(conn, '/error/3')
  66. elif name in get_default_admin_group():
  67. return re_error(conn, '/error/3')
  68. curs.execute(db_change("delete from alist where name = ?"), [name])
  69. for for_a in acl_name_list:
  70. if flask.request.form.get(for_a[1], 0) != 0:
  71. curs.execute(db_change("insert into alist (name, acl) values (?, ?)"), [name, for_a[1]])
  72. return redirect(conn, '/auth/list/add/' + url_pas(name))
  73. else:
  74. state = 'disabled' if acl_check('', 'owner_auth', '', '') == 1 else ''
  75. state = 'disabled' if name in get_default_admin_group() else state
  76. data = '<ul>'
  77. for for_a in acl_name_list:
  78. curs.execute(db_change('select acl from alist where name = ?'), [name])
  79. acl_list = curs.fetchall()
  80. acl_list = [for_a[0] for for_a in acl_list]
  81. checked = ''
  82. choice = '<input type="checkbox" ' + state + ' name="' + for_a[1] + '" ' + checked + '> ' + for_a[2]
  83. if for_a[1] == '':
  84. choice = for_a[2]
  85. elif for_a[1] in acl_list:
  86. checked = 'checked'
  87. data += '' + \
  88. '<li class="opennamu_list_1" style="margin-left: ' + str(int(for_a[0]) * 20) + 'px;">' + \
  89. choice + \
  90. '</li>'
  91. ''
  92. data += '</ul>'
  93. return easy_minify(conn, flask.render_template(skin_check(conn),
  94. imp = [name, wiki_set(conn), wiki_custom(conn), wiki_css(['(' + get_lang(conn, 'admin_group') + ')', 0])],
  95. data = '''
  96. <form method="post">
  97. ''' + data + '''
  98. <hr class="main_hr">
  99. <button ''' + state + ''' type="submit">''' + get_lang(conn, 'save') + '''</button>
  100. </form>
  101. ''',
  102. menu = [['auth/list', get_lang(conn, 'return')]]
  103. ))