give_admin_groups.py 7.1 KB

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