landed Delete Community
This commit is contained in:
@@ -730,6 +730,40 @@ func CommunityEmail(ctxt ui.AmContext) (string, any) {
|
|||||||
return "redirect", fmt.Sprintf("/comm/%s/admin", comm.Alias)
|
return "redirect", fmt.Sprintf("/comm/%s/admin", comm.Alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* DeleteCommunity handles the deletion of a community.
|
||||||
|
* Parameters:
|
||||||
|
* ctxt - The AmContext for the request.
|
||||||
|
* Returns:
|
||||||
|
* Command string dictating what to be rendered.
|
||||||
|
* Data as a parameter for the command string.
|
||||||
|
* Standard Go error status.
|
||||||
|
*/
|
||||||
|
func DeleteCommunity(ctxt ui.AmContext) (string, any) {
|
||||||
|
comm := ctxt.CurrentCommunity()
|
||||||
|
if !comm.TestPermission("Community.Delete", ctxt.EffectiveLevel()) {
|
||||||
|
return "error", ENOACCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the message box, and, if we have a valid "yes," then perform the delete
|
||||||
|
mbox, err := ui.AmLoadMessageBox("deleteComm")
|
||||||
|
if err != nil {
|
||||||
|
return "error", err
|
||||||
|
}
|
||||||
|
if mbox.Validate(ctxt, "yes") {
|
||||||
|
err := comm.Delete(ctxt.Ctx(), ctxt.CurrentUser(), ctxt.RemoteIP(), ampool)
|
||||||
|
if err != nil {
|
||||||
|
return "error", err
|
||||||
|
}
|
||||||
|
return "redirect", "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up to display the message box.
|
||||||
|
mbox.SetMessage(fmt.Sprintf(`You are about to <b>permanently</b> delete the <span class="font-bold text-red-600">"%s"</span> community!`, comm.Name))
|
||||||
|
mbox.SetLink("no", fmt.Sprintf("/comm/%s/admin", comm.Alias))
|
||||||
|
mbox.SetLink("yes", fmt.Sprintf("/comm/%s/admin/delete", comm.Alias))
|
||||||
|
return mbox.Render(ctxt)
|
||||||
|
}
|
||||||
|
|
||||||
/* CreateCommunityForm renders the form for creating a new community.
|
/* CreateCommunityForm renders the form for creating a new community.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ctxt - The AmContext for the request.
|
* ctxt - The AmContext for the request.
|
||||||
|
|||||||
@@ -591,6 +591,51 @@ func (c *Community) GetMemberEMailAddrs(ctx context.Context) ([]string, error) {
|
|||||||
return rc, err
|
return rc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete deletes this community.
|
||||||
|
func (c *Community) Delete(ctx context.Context, u *User, ipaddr string, background *util.WorkerPool) error {
|
||||||
|
tx, commit, rollback := transaction(ctx)
|
||||||
|
defer rollback()
|
||||||
|
|
||||||
|
// Start by deleting all the community's services. This will purge the conferences, among other things.
|
||||||
|
err := AmDeleteCommunityServices(ctx, tx, c.Id, background)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now erase from the other tables as well: members, bans, properties, and communities themselves.
|
||||||
|
_, err = tx.ExecContext(ctx, "DELETE FROM commmember WHERE commid = ?", c.Id)
|
||||||
|
if err == nil {
|
||||||
|
_, err = tx.ExecContext(ctx, "DELETE FROM commban WHERE commid = ?", c.Id)
|
||||||
|
if err == nil {
|
||||||
|
_, err = tx.ExecContext(ctx, "DELETE FROM propcomm WHERE cid = ?", c.Id)
|
||||||
|
if err == nil {
|
||||||
|
_, err = tx.ExecContext(ctx, "DELETE FROM communities WHERE commid = ?", c.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = commit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Purge the member and properties caches, and punt this community from the community cache.
|
||||||
|
memberMutex.Lock()
|
||||||
|
memberCache.Purge()
|
||||||
|
memberMutex.Unlock()
|
||||||
|
getCommunityPropMutex.Lock()
|
||||||
|
communityPropCache.Purge()
|
||||||
|
getCommunityPropMutex.Unlock()
|
||||||
|
getCommunityMutex.Lock()
|
||||||
|
communityCache.Remove(c.Id)
|
||||||
|
getCommunityMutex.Unlock()
|
||||||
|
|
||||||
|
// Save off an audit record for the delete.
|
||||||
|
AmStoreAudit(AmNewCommAudit(AuditCommunityDelete, u.Uid, c.Id, ipaddr))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
/* AmGetCommunity returns a reference to the specified community.
|
/* AmGetCommunity returns a reference to the specified community.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ctx - Standard Go context value.
|
* ctx - Standard Go context value.
|
||||||
|
|||||||
@@ -937,6 +937,11 @@ func (*conferenceServiceVTable) OnDeleteCommunity(ctx context.Context, tx *sqlx.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Delete any mention of this community from the conference hotlists.
|
||||||
|
_, err = tx.ExecContext(ctx, "DELETE FROM confhotlist WHERE commid = ?", commid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for i, confid := range confids {
|
for i, confid := range confids {
|
||||||
// any references to conference other than this community?
|
// any references to conference other than this community?
|
||||||
refCount := 0
|
refCount := 0
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ _(italicized items can be deferred)_
|
|||||||
- ~~Manage (reorder/show/hide/delete)~~
|
- ~~Manage (reorder/show/hide/delete)~~
|
||||||
- ~~Create New~~
|
- ~~Create New~~
|
||||||
- ~~Conferences List honor "hide in list" flag~~
|
- ~~Conferences List honor "hide in list" flag~~
|
||||||
- Community Admin Menu:
|
- ~~Community Admin Menu:~~
|
||||||
- ~~Set Community Category~~
|
- ~~Set Community Category~~
|
||||||
- ~~Membership Control~~
|
- ~~Membership Control~~
|
||||||
- ~~E-Mail to All Members~~
|
- ~~E-Mail to All Members~~
|
||||||
- ~~Display Audit Records~~
|
- ~~Display Audit Records~~
|
||||||
- Delete Community
|
- ~~Delete Community~~
|
||||||
- ~~Community Profile: Invite~~
|
- ~~Community Profile: Invite~~
|
||||||
- _Help link atop page headers_
|
- _Help link atop page headers_
|
||||||
- _Policy page_
|
- _Policy page_
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ func setupEcho() *echo.Echo {
|
|||||||
adminGroup.Match(GetAndPost, "/members", ui.AmWrap(CommunityMembers))
|
adminGroup.Match(GetAndPost, "/members", ui.AmWrap(CommunityMembers))
|
||||||
adminGroup.GET("/massmail", ui.AmWrap(CommunityEmailForm))
|
adminGroup.GET("/massmail", ui.AmWrap(CommunityEmailForm))
|
||||||
adminGroup.POST("/massmail", ui.AmWrap(CommunityEmail))
|
adminGroup.POST("/massmail", ui.AmWrap(CommunityEmail))
|
||||||
|
adminGroup.GET("/delete", ui.AmWrap(DeleteCommunity))
|
||||||
|
|
||||||
// conference group
|
// conference group
|
||||||
commGroup.GET("/create_conf", ui.AmWrap(CreateConferenceForm))
|
commGroup.GET("/create_conf", ui.AmWrap(CreateConferenceForm))
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ menudefs:
|
|||||||
link: "/comm/[CID]/admin/audit"
|
link: "/comm/[CID]/admin/audit"
|
||||||
permission: "Community.ShowAdmin"
|
permission: "Community.ShowAdmin"
|
||||||
- text: "Delete Community"
|
- text: "Delete Community"
|
||||||
link: "/TODO/comm/[CID]/admin/delete"
|
link: "/comm/[CID]/admin/delete"
|
||||||
permission: "Community.Delete"
|
permission: "Community.Delete"
|
||||||
hazard: true
|
hazard: true
|
||||||
- id: "confhost"
|
- id: "confhost"
|
||||||
|
|||||||
@@ -105,3 +105,31 @@ messagedefs:
|
|||||||
tone: "green"
|
tone: "green"
|
||||||
icon: "✗"
|
icon: "✗"
|
||||||
text: "No, Cancel"
|
text: "No, Cancel"
|
||||||
|
- id: "deleteComm"
|
||||||
|
title: "Delete Community"
|
||||||
|
tone: "red"
|
||||||
|
destructive: true
|
||||||
|
message: "You are about to delete a community!"
|
||||||
|
warningIcon: "💣"
|
||||||
|
warningLines:
|
||||||
|
- text: "Warning: This action cannot be undone!"
|
||||||
|
bold: true
|
||||||
|
- text: "Deleting this community will permanently remove it and all its contents from the system."
|
||||||
|
bold: false
|
||||||
|
- text: "Hundreds or even thousands of individual contributions will be lost forever."
|
||||||
|
bold: false
|
||||||
|
- text: "Please consider this action very carefully!"
|
||||||
|
bold: true
|
||||||
|
buttons:
|
||||||
|
- id: "yes"
|
||||||
|
link: "placeholder"
|
||||||
|
confirm: true
|
||||||
|
tone: "red"
|
||||||
|
icon: "✓"
|
||||||
|
text: "Yes, Delete It"
|
||||||
|
- id: "no"
|
||||||
|
link: "placeholder"
|
||||||
|
confirm: false
|
||||||
|
tone: "green"
|
||||||
|
icon: "✗"
|
||||||
|
text: "No, Cancel"
|
||||||
|
|||||||
Reference in New Issue
Block a user