2018-09-30 00:08:27 +00:00
|
|
|
package panel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
c "github.com/Azareal/Gosora/common"
|
2018-11-01 06:43:56 +00:00
|
|
|
"github.com/Azareal/Gosora/common/phrases"
|
2018-09-30 00:08:27 +00:00
|
|
|
)
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func Groups(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
2018-09-30 00:42:33 +00:00
|
|
|
basePage, ferr := buildBasePage(w, r, &user, "groups", "groups")
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
|
|
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
2018-12-06 11:09:10 +00:00
|
|
|
perPage := 15
|
2019-04-19 08:20:10 +00:00
|
|
|
offset, page, lastPage := c.PageOffset(basePage.Stats.Groups, page, perPage)
|
2018-09-30 00:08:27 +00:00
|
|
|
|
|
|
|
// Skip the 'Unknown' group
|
|
|
|
offset++
|
|
|
|
|
|
|
|
var count int
|
2019-04-19 08:20:10 +00:00
|
|
|
var groupList []c.GroupAdmin
|
|
|
|
groups, _ := c.Groups.GetRange(offset, 0)
|
2018-09-30 00:08:27 +00:00
|
|
|
for _, group := range groups {
|
|
|
|
if count == perPage {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
var rank string
|
|
|
|
var rankClass string
|
|
|
|
var canDelete = false
|
|
|
|
|
|
|
|
// TODO: Use a switch for this
|
|
|
|
// TODO: Localise this
|
|
|
|
if group.IsAdmin {
|
|
|
|
rank = "Admin"
|
|
|
|
rankClass = "admin"
|
|
|
|
} else if group.IsMod {
|
|
|
|
rank = "Mod"
|
|
|
|
rankClass = "mod"
|
|
|
|
} else if group.IsBanned {
|
|
|
|
rank = "Banned"
|
|
|
|
rankClass = "banned"
|
|
|
|
} else if group.ID == 6 {
|
|
|
|
rank = "Guest"
|
|
|
|
rankClass = "guest"
|
|
|
|
} else {
|
|
|
|
rank = "Member"
|
|
|
|
rankClass = "member"
|
|
|
|
}
|
|
|
|
|
2018-09-30 00:42:33 +00:00
|
|
|
canEdit := user.Perms.EditGroup && (!group.IsAdmin || user.Perms.EditGroupAdmin) && (!group.IsMod || user.Perms.EditGroupSuperMod)
|
2019-04-19 08:20:10 +00:00
|
|
|
groupList = append(groupList, c.GroupAdmin{group.ID, group.Name, rank, rankClass, canEdit, canDelete})
|
2018-09-30 00:08:27 +00:00
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
2019-06-04 05:48:12 +00:00
|
|
|
pageList := c.Paginate(page, lastPage, 5)
|
2019-04-19 08:20:10 +00:00
|
|
|
pi := c.PanelGroupPage{basePage, groupList, c.Paginator{pageList, page, lastPage}}
|
2019-04-29 08:17:12 +00:00
|
|
|
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage,"","","panel_groups",&pi})
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func GroupsEdit(w http.ResponseWriter, r *http.Request, user c.User, sgid string) c.RouteError {
|
2018-09-30 00:42:33 +00:00
|
|
|
basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups")
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
if !user.Perms.EditGroup {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NoPermissions(w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid, err := strconv.Atoi(sgid)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("url_id_must_be_integer"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
group, err := c.Groups.Get(gid)
|
2018-09-30 00:08:27 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
//log.Print("aaaaa monsters")
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NotFound(w, r, basePage.Header)
|
2018-09-30 00:08:27 +00:00
|
|
|
} else if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if group.IsAdmin && !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
if group.IsMod && !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var rank string
|
|
|
|
switch {
|
|
|
|
case group.IsAdmin:
|
|
|
|
rank = "Admin"
|
|
|
|
case group.IsMod:
|
|
|
|
rank = "Mod"
|
|
|
|
case group.IsBanned:
|
|
|
|
rank = "Banned"
|
|
|
|
case group.ID == 6:
|
|
|
|
rank = "Guest"
|
|
|
|
default:
|
|
|
|
rank = "Member"
|
|
|
|
}
|
|
|
|
disableRank := !user.Perms.EditGroupGlobalPerms || (group.ID == 6)
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
pi := c.PanelEditGroupPage{basePage, group.ID, group.Name, group.Tag, rank, disableRank}
|
2019-02-10 05:52:26 +00:00
|
|
|
return renderTemplate("panel_group_edit", w, r, basePage.Header, pi)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func GroupsEditPerms(w http.ResponseWriter, r *http.Request, user c.User, sgid string) c.RouteError {
|
2018-09-30 00:42:33 +00:00
|
|
|
basePage, ferr := buildBasePage(w, r, &user, "edit_group", "groups")
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
if !user.Perms.EditGroup {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NoPermissions(w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid, err := strconv.Atoi(sgid)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("url_id_must_be_integer"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
group, err := c.Groups.Get(gid)
|
2018-09-30 00:08:27 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
//log.Print("aaaaa monsters")
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NotFound(w, r, basePage.Header)
|
2018-09-30 00:08:27 +00:00
|
|
|
} else if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if group.IsAdmin && !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
if group.IsMod && !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Load the phrases in bulk for efficiency?
|
2019-04-19 08:20:10 +00:00
|
|
|
var localPerms []c.NameLangToggle
|
2018-09-30 00:08:27 +00:00
|
|
|
|
|
|
|
var addLocalPerm = func(permStr string, perm bool) {
|
2019-04-19 08:20:10 +00:00
|
|
|
localPerms = append(localPerms, c.NameLangToggle{permStr, phrases.GetLocalPermPhrase(permStr), perm})
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addLocalPerm("ViewTopic", group.Perms.ViewTopic)
|
|
|
|
addLocalPerm("LikeItem", group.Perms.LikeItem)
|
|
|
|
addLocalPerm("CreateTopic", group.Perms.CreateTopic)
|
|
|
|
//<--
|
|
|
|
addLocalPerm("EditTopic", group.Perms.EditTopic)
|
|
|
|
addLocalPerm("DeleteTopic", group.Perms.DeleteTopic)
|
|
|
|
addLocalPerm("CreateReply", group.Perms.CreateReply)
|
|
|
|
addLocalPerm("EditReply", group.Perms.EditReply)
|
|
|
|
addLocalPerm("DeleteReply", group.Perms.DeleteReply)
|
|
|
|
addLocalPerm("PinTopic", group.Perms.PinTopic)
|
|
|
|
addLocalPerm("CloseTopic", group.Perms.CloseTopic)
|
|
|
|
addLocalPerm("MoveTopic", group.Perms.MoveTopic)
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
var globalPerms []c.NameLangToggle
|
2018-09-30 00:08:27 +00:00
|
|
|
var addGlobalPerm = func(permStr string, perm bool) {
|
2019-04-19 08:20:10 +00:00
|
|
|
globalPerms = append(globalPerms, c.NameLangToggle{permStr, phrases.GetGlobalPermPhrase(permStr), perm})
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addGlobalPerm("BanUsers", group.Perms.BanUsers)
|
|
|
|
addGlobalPerm("ActivateUsers", group.Perms.ActivateUsers)
|
|
|
|
addGlobalPerm("EditUser", group.Perms.EditUser)
|
|
|
|
addGlobalPerm("EditUserEmail", group.Perms.EditUserEmail)
|
|
|
|
addGlobalPerm("EditUserPassword", group.Perms.EditUserPassword)
|
|
|
|
addGlobalPerm("EditUserGroup", group.Perms.EditUserGroup)
|
|
|
|
addGlobalPerm("EditUserGroupSuperMod", group.Perms.EditUserGroupSuperMod)
|
|
|
|
addGlobalPerm("EditUserGroupAdmin", group.Perms.EditUserGroupAdmin)
|
|
|
|
addGlobalPerm("EditGroup", group.Perms.EditGroup)
|
|
|
|
addGlobalPerm("EditGroupLocalPerms", group.Perms.EditGroupLocalPerms)
|
|
|
|
addGlobalPerm("EditGroupGlobalPerms", group.Perms.EditGroupGlobalPerms)
|
|
|
|
addGlobalPerm("EditGroupSuperMod", group.Perms.EditGroupSuperMod)
|
|
|
|
addGlobalPerm("EditGroupAdmin", group.Perms.EditGroupAdmin)
|
|
|
|
addGlobalPerm("ManageForums", group.Perms.ManageForums)
|
|
|
|
addGlobalPerm("EditSettings", group.Perms.EditSettings)
|
|
|
|
addGlobalPerm("ManageThemes", group.Perms.ManageThemes)
|
|
|
|
addGlobalPerm("ManagePlugins", group.Perms.ManagePlugins)
|
|
|
|
addGlobalPerm("ViewAdminLogs", group.Perms.ViewAdminLogs)
|
|
|
|
addGlobalPerm("ViewIPs", group.Perms.ViewIPs)
|
|
|
|
addGlobalPerm("UploadFiles", group.Perms.UploadFiles)
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
pi := c.PanelEditGroupPermsPage{basePage, group.ID, group.Name, localPerms, globalPerms}
|
2019-02-10 05:52:26 +00:00
|
|
|
return renderTemplate("panel_group_edit_perms", w, r, basePage.Header, pi)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func GroupsEditSubmit(w http.ResponseWriter, r *http.Request, user c.User, sgid string) c.RouteError {
|
|
|
|
_, ferr := c.SimplePanelUserCheck(w, r, &user)
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
if !user.Perms.EditGroup {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NoPermissions(w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid, err := strconv.Atoi(sgid)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("id_must_be_integer"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
group, err := c.Groups.Get(gid)
|
2018-09-30 00:08:27 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
//log.Print("aaaaa monsters")
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NotFound(w, r, nil)
|
2018-09-30 00:08:27 +00:00
|
|
|
} else if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if group.IsAdmin && !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
if group.IsMod && !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gname := r.FormValue("group-name")
|
|
|
|
if gname == "" {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_need_name"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
gtag := r.FormValue("group-tag")
|
|
|
|
rank := r.FormValue("group-type")
|
|
|
|
|
|
|
|
var originalRank string
|
|
|
|
// TODO: Use a switch for this
|
|
|
|
if group.IsAdmin {
|
|
|
|
originalRank = "Admin"
|
|
|
|
} else if group.IsMod {
|
|
|
|
originalRank = "Mod"
|
|
|
|
} else if group.IsBanned {
|
|
|
|
originalRank = "Banned"
|
|
|
|
} else if group.ID == 6 {
|
|
|
|
originalRank = "Guest"
|
|
|
|
} else {
|
|
|
|
originalRank = "Member"
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:10:55 +00:00
|
|
|
if rank != originalRank && originalRank != "Guest" {
|
2018-09-30 00:08:27 +00:00
|
|
|
if !user.Perms.EditGroupGlobalPerms {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_group_type"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch rank {
|
|
|
|
case "Admin":
|
|
|
|
if !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_edit_cannot_designate_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
err = group.ChangeRank(true, true, false)
|
|
|
|
case "Mod":
|
|
|
|
if !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_edit_cannot_designate_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
err = group.ChangeRank(false, true, false)
|
|
|
|
case "Banned":
|
|
|
|
err = group.ChangeRank(false, false, true)
|
|
|
|
case "Guest":
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_be_guest"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
case "Member":
|
|
|
|
err = group.ChangeRank(false, false, false)
|
|
|
|
default:
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_invalid_group_type"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = group.Update(gname, gtag)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
http.Redirect(w, r, "/panel/groups/edit/"+strconv.Itoa(gid), http.StatusSeeOther)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func GroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user c.User, sgid string) c.RouteError {
|
|
|
|
_, ferr := c.SimplePanelUserCheck(w, r, &user)
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
if !user.Perms.EditGroup {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NoPermissions(w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid, err := strconv.Atoi(sgid)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("id_must_be_integer"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
group, err := c.Groups.Get(gid)
|
2018-09-30 00:08:27 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
//log.Print("aaaaa monsters o.o")
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NotFound(w, r, nil)
|
2018-09-30 00:08:27 +00:00
|
|
|
} else if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if group.IsAdmin && !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
if group.IsMod && !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_cannot_edit_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var pmap = make(map[string]bool)
|
|
|
|
|
|
|
|
if user.Perms.EditGroupLocalPerms {
|
2019-04-19 08:20:10 +00:00
|
|
|
for _, perm := range c.LocalPermList {
|
2018-09-30 00:08:27 +00:00
|
|
|
pvalue := r.PostFormValue("group-perm-" + perm)
|
|
|
|
pmap[perm] = (pvalue == "1")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Perms.EditGroupGlobalPerms {
|
2019-04-19 08:20:10 +00:00
|
|
|
for _, perm := range c.GlobalPermList {
|
2018-09-30 00:08:27 +00:00
|
|
|
pvalue := r.PostFormValue("group-perm-" + perm)
|
|
|
|
pmap[perm] = (pvalue == "1")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = group.UpdatePerms(pmap)
|
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
http.Redirect(w, r, "/panel/groups/edit/perms/"+strconv.Itoa(gid), http.StatusSeeOther)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
func GroupsCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
|
|
|
|
_, ferr := c.SimplePanelUserCheck(w, r, &user)
|
2018-09-30 00:08:27 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
|
|
|
if !user.Perms.EditGroup {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.NoPermissions(w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
groupName := r.PostFormValue("group-name")
|
|
|
|
if groupName == "" {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_need_name"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
groupTag := r.PostFormValue("group-tag")
|
|
|
|
|
|
|
|
var isAdmin, isMod, isBanned bool
|
|
|
|
if user.Perms.EditGroupGlobalPerms {
|
|
|
|
groupType := r.PostFormValue("group-type")
|
|
|
|
if groupType == "Admin" {
|
|
|
|
if !user.Perms.EditGroupAdmin {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_create_cannot_designate_admin"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
isAdmin = true
|
|
|
|
isMod = true
|
|
|
|
} else if groupType == "Mod" {
|
|
|
|
if !user.Perms.EditGroupSuperMod {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.LocalError(phrases.GetErrorPhrase("panel_groups_create_cannot_designate_supermod"), w, r, user)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
isMod = true
|
|
|
|
} else if groupType == "Banned" {
|
|
|
|
isBanned = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
gid, err := c.Groups.Create(groupName, groupTag, isAdmin, isMod, isBanned)
|
2018-09-30 00:08:27 +00:00
|
|
|
if err != nil {
|
2019-04-19 08:20:10 +00:00
|
|
|
return c.InternalError(err, w, r)
|
2018-09-30 00:08:27 +00:00
|
|
|
}
|
|
|
|
http.Redirect(w, r, "/panel/groups/edit/"+strconv.Itoa(gid), http.StatusSeeOther)
|
|
|
|
return nil
|
|
|
|
}
|