Bläddra i källkod

투표 개설 권한 하향

https://github.com/openNAMU/openNAMU/issues/2215
잉여개발기 2 år sedan
förälder
incheckning
9be55c7673
6 ändrade filer med 26 tillägg och 12 borttagningar
  1. 6 2
      route/tool/func.py
  2. 5 1
      route/vote_add.py
  3. 7 1
      route/vote_close.py
  4. 4 5
      route/vote_end.py
  5. 3 2
      route/vote_list.py
  6. 1 1
      version.json

+ 6 - 2
route/tool/func.py

@@ -1832,7 +1832,7 @@ def admin_check(conn, num = None, what = None, name = ''):
 
     return 0
 
-def acl_check(conn, name = '', tool = '', topic_num = '1'):
+def acl_check(conn, name = '', tool = '', topic_num = ''):
     curs = conn.cursor()
 
     if name == None:
@@ -1945,7 +1945,10 @@ def acl_check(conn, name = '', tool = '', topic_num = '1'):
             num = 5
         elif tool == 'vote':
             if i == 0:
-                curs.execute(db_change('select acl from vote where id = ? and user = ""'), [topic_num])
+                if topic_num != '':
+                    curs.execute(db_change('select acl from vote where id = ? and user = ""'), [topic_num])
+                else:
+                    continue
             else:
                 curs.execute(db_change('select data from other where name = "vote_acl"'))
 
@@ -2001,6 +2004,7 @@ def acl_check(conn, name = '', tool = '', topic_num = '1'):
             num = 5
 
         acl_data = curs.fetchall()
+        print(i, acl_data, topic_num)
         if not acl_data or acl_data[0][0] == '':
             if tool == 'recaptcha':
                 acl_data = [['admin']]

+ 5 - 1
route/vote_add.py

@@ -4,7 +4,7 @@ def vote_add():
     with get_db_connect() as conn:
         curs = conn.cursor()
 
-        if admin_check(conn) != 1:
+        if acl_check(conn, '', 'vote') == 1:
             return re_error(conn, '/ban')
 
         if flask.request.method == 'POST':
@@ -31,6 +31,10 @@ def vote_add():
                 open_data,
                 flask.request.form.get('acl_select', '')
             ])
+            curs.execute(db_change("insert into vote (name, id, subject, data, user, type, acl) values ('open_user', ?, '', ?, '', 'option', '')"), [
+                id_data,
+                ip_check()
+            ])
             
             time_limitless = flask.request.form.get('limitless', '')
             if time_limitless == '':

+ 7 - 1
route/vote_close.py

@@ -6,7 +6,7 @@ def vote_close(num = 1):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
-        if admin_check(conn) != 1:
+        if acl_check(conn, '', 'vote') == 1:
             return re_error(conn, '/ban')
 
         curs.execute(db_change('select type from vote where id = ? and user = ""'), [num])
@@ -14,6 +14,12 @@ def vote_close(num = 1):
         if not data_list:
             return redirect(conn, '/vote')
 
+        curs.execute(db_change('select data from vote where id = ? and name = "open_user" and type = "option"'), [num])
+        db_data = curs.fetchall()
+        open_user = db_data[0][0] if db_data else ''
+        if open_user != ip_check() and admin_check(conn) != 1:
+            return re_error(conn, '/ban')
+
         if data_list[0][0] == 'close':
             type_set = 'open'
         elif data_list[0][0] == 'n_close':

+ 4 - 5
route/vote_end.py

@@ -12,11 +12,10 @@ def vote_end(num = 1):
             return redirect(conn, '/vote')
 
         data = ''
-        if admin_check(conn) == 1:
-            if data_list[0][3] == 'open' or data_list[0][3] == 'n_open':
-                data += '<a href="/vote/close/' + num + '">(' + get_lang(conn, 'close_vote') + ')</a>'
-            else:
-                data += '<a href="/vote/close/' + num + '">(' + get_lang(conn, 're_open_vote') + ')</a>'
+        if data_list[0][3] == 'open' or data_list[0][3] == 'n_open':
+            data += '<a href="/vote/close/' + num + '">(' + get_lang(conn, 'close_vote') + ')</a>'
+        else:
+            data += '<a href="/vote/close/' + num + '">(' + get_lang(conn, 're_open_vote') + ')</a>'
         
         curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [num])
         db_data = curs.fetchall()

+ 3 - 2
route/vote_list.py

@@ -28,8 +28,9 @@ def vote_list(list_type = 'normal', num = 1):
             data += '<li><a href="/vote/' + i[1] + '">' + i[1] + '. ' + html.escape(i[0]) + '</a> (' + open_select + ')</li>'
 
         data += '</ul>'
+        menu = []
         if list_type == 'normal':
-            data += ('<a href="/vote/add">(' + get_lang(conn, 'add_vote') + ')</a>') if admin_check(conn) == 1 else ''
+            menu = [["vote/add", get_lang(conn, 'add_vote')]] if acl_check(conn, '', 'vote') != 1 else []
             data += next_fix(conn, '/vote/list/', num, data_list)
         else:
             data += next_fix(conn, '/vote/list/close/', num, data_list)
@@ -37,5 +38,5 @@ def vote_list(list_type = 'normal', num = 1):
         return easy_minify(conn, flask.render_template(skin_check(conn),
             imp = [get_lang(conn, 'vote_list'), wiki_set(conn), wiki_custom(conn), wiki_css([sub, 0])],
             data = data,
-            menu = [['other', get_lang(conn, 'return')]]
+            menu = [['other', get_lang(conn, 'return')]] + menu
         ))

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.5.0-v124",
+        "r_ver" : "v3.5.0-v125",
         "c_ver" : "20240513",
         "s_ver" : "20240426"
     }