| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package route
- import (
- "opennamu/route/tool"
- )
- func Api_give_auth_patch(config tool.Config) string {
- db := tool.DB_connect()
- defer tool.DB_close(db)
- other_set := map[string]string{}
- json.Unmarshal([]byte(config.Other_set), &other_set)
- new_data := make(map[string]any)
- ip := config.IP
- user_name := other_set["user_name"]
- if user_name != "" {
- auth_check := false
- auth_name := tool.Get_user_auth(db, user_name)
- auth_data := tool.Get_auth_group_info(db, auth_name)
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", ip) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", ip) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- auth_check = false
- auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", ip) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", ip) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- tool.Exec_DB(
- db,
- "delete from user_set where id = ? and name = 'acl'",
- user_name,
- )
- tool.Exec_DB(
- db,
- "insert into user_set (id, name, data) values (?, 'acl', ?)",
- user_name, other_set["change_auth"],
- )
-
- new_data["response"] = "ok"
- }
- }
- } else {
- auth_check := false
- auth_data := tool.Get_auth_group_info(db, other_set["auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", config.IP) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", config.IP) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- auth_check = false
- auth_data = tool.Get_auth_group_info(db, other_set["change_auth"])
- if tool.Auth_include_upper_auth(auth_data) {
- if tool.Check_acl(db, "", "", "owner_auth", config.IP) {
- auth_check = true
- }
- } else {
- if tool.Check_acl(db, "", "", "give_auth", config.IP) {
- auth_check = true
- }
- }
- if !auth_check {
- new_data["response"] = "require auth"
- } else {
- tool.Exec_DB(
- db,
- "update user_set set data = ? where name = 'acl' and data = ?",
- other_set["change_auth"], other_set["auth"],
- )
- new_data["response"] = "ok"
- }
- }
- }
- json_data, _ := json.Marshal(new_data)
- return string(json_data)
- }
|