login
Self-hosted web frontend for git repositories written in Go.
summary tree log refs contributors
f3ad0106e2a86d40994650928518e07d385dc678
9 days ago
Nirmal Almara
remove repo member functionality
4 files changed, 38 insertions(+)
@@ -109,6 +109,9 @@ func RunWeb(conf *setting.BaseStruct) {

m.HandleFunc("/r/{reponame}/meta/user", func(w http.ResponseWriter, r *http.Request) {

handler.PostRepoMetaUser(w, r, db, conf, decoder)

}).Methods("POST")

+ m.HandleFunc("/r/{reponame}/meta/user/remove/{username}", func(w http.ResponseWriter, r *http.Request) {

+ handler.RemoveRepoMetaUser(w, r, db, conf)

+ }).Methods("GET")

m.HandleFunc("/r/{reponame}/meta/delete", func(w http.ResponseWriter, r *http.Request) {

handler.PostRepoMetaDelete(w, r, db, conf)

}).Methods("POST")

@@ -579,6 +579,29 @@ func PostRepoMeta(w http.ResponseWriter, r *http.Request, db *sql.DB, conf *sett

http.Redirect(w, r, "/login", http.StatusFound)

}

+// RemoveRepoMetaUser ...

+func RemoveRepoMetaUser(w http.ResponseWriter, r *http.Request, db *sql.DB, conf *setting.BaseStruct) {

+ userPresent := w.Header().Get("user-present")

+ vars := mux.Vars(r)

+ reponame := vars["reponame"]

+ username := vars["username"]

+

+ if userPresent == "true" {

+ token := w.Header().Get("sorcia-cookie-token")

+ loggedInUserID := model.GetUserIDFromToken(db, token)

+

+ if model.CheckRepoOwnerFromUserIDAndReponame(db, loggedInUserID, reponame) {

+ userIDToRemove := model.GetUserIDFromUsername(db, username)

+ repoID := model.GetRepoIDFromReponame(db, reponame)

+ model.RemoveRepoMember(db, userIDToRemove, repoID)

+

+ http.Redirect(w, r, "/r/"+reponame+"/meta", http.StatusFound)

+ return

+ }

+ }

+ http.Redirect(w, r, "/r/"+reponame+"/meta", http.StatusFound)

+}

+

// PostRepoMetaMember struct

type PostRepoMetaMember struct {

Username string `schema:"username"`

@@ -83,6 +83,15 @@ func InsertRepoMember(db *sql.DB, crm CreateRepoMember) {

errorhandler.CheckError("Error on model insert repo member exec", err)

}

+// RemoveRepoMember ...

+func RemoveRepoMember(db *sql.DB, userID, repoID int) {

+ stmt, err := db.Prepare("DELETE FROM repository_members WHERE user_id = ? AND repo_id = ?")

+ errorhandler.CheckError("Error on model remove repo member", err)

+

+ _, err = stmt.Exec(userID, repoID)

+ errorhandler.CheckError("Error on model remove repo member exec", err)

+}

+

// GetRepoMembersStruct struct

type GetRepoMembersStruct struct {

RepoMembers []RepoMember

@@ -106,6 +106,9 @@

<p class="owner">[Owner]</p>

{{end}}

<p>({{.Permission}})</p>

+ {{if not .IsOwner}}

+ <a onclick="return confirm('Are you sure, you want to remove this user?');" href="/r/{{$.Reponame}}/meta/user/remove/{{.Username}}" class="button button--danger">Remove</a>

+ {{end}}

</div>

{{end}}

</div>