diff options
author | 2024-07-08 22:10:44 +0300 | |
---|---|---|
committer | 2024-07-08 22:10:44 +0300 | |
commit | 28c03550e4e46d011cd055b4dfab0428209acb49 (patch) | |
tree | 31a0d8c0eb7276429006f6fbd9c364d08366c0cf | |
parent | app/preferences: remove previously created cookies (diff) | |
download | soko-28c03550e4e46d011cd055b4dfab0428209acb49.tar.gz soko-28c03550e4e46d011cd055b4dfab0428209acb49.tar.bz2 soko-28c03550e4e46d011cd055b4dfab0428209acb49.zip |
app/preferences: remove maintainers
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/handler/maintainer/show.go | 14 | ||||
-rw-r--r-- | pkg/app/handler/user/maintainers.templ | 93 | ||||
-rw-r--r-- | pkg/app/handler/user/preferences.templ | 50 | ||||
-rw-r--r-- | pkg/app/serve.go | 8 | ||||
-rw-r--r-- | pkg/app/utils/userdata.go | 26 | ||||
-rw-r--r-- | pkg/models/userpreferences.go | 23 |
6 files changed, 6 insertions, 208 deletions
diff --git a/pkg/app/handler/maintainer/show.go b/pkg/app/handler/maintainer/show.go index 410854b..1103724 100644 --- a/pkg/app/handler/maintainer/show.go +++ b/pkg/app/handler/maintainer/show.go @@ -37,15 +37,11 @@ func common(w http.ResponseWriter, r *http.Request) (maintainer models.Maintaine return } - userPreferences := utils.GetUserPreferences(r) - if userPreferences.Maintainers.IncludeProjectPackages && maintainer.Projects != nil && len(maintainer.Projects) > 0 { - excludeList := strings.Join(userPreferences.Maintainers.ExcludedProjects, ",") - for _, proj := range maintainer.Projects { - if !strings.Contains(excludeList, proj.Email) { - packagesQuery = packagesQuery.WhereOr("maintainers @> ?", `[{"Email": "`+proj.Email+`"}]`) - } - } - } + // if IncludeProjectPackages { + // for _, proj := range maintainer.Projects { + // packagesQuery = packagesQuery.WhereOr("maintainers @> ?", `[{"Email": "`+proj.Email+`"}]`) + // } + // } packagesCount, err = packagesQuery.Clone().Count() if err != nil { diff --git a/pkg/app/handler/user/maintainers.templ b/pkg/app/handler/user/maintainers.templ deleted file mode 100644 index 10d4b9c..0000000 --- a/pkg/app/handler/user/maintainers.templ +++ /dev/null @@ -1,93 +0,0 @@ -package user - -import ( - "encoding/base64" - "encoding/json" - "net/http" - "slices" - "soko/pkg/app/utils" - "soko/pkg/database" - "soko/pkg/models" - "time" -) - -func splitAllProjects() [][]models.Project { - var projects []models.Project - database.DBCon.Model(&projects).Column("name", "email").Select() - split := (3 + len(projects)) / 4 - return [][]models.Project{projects[:split], projects[split : 2*split], projects[2*split : 3*split], projects[3*split:]} -} - -templ maintainers(preferences models.MaintainersPreferences) { - <form method="post" action="/user/preferences/maintainers/edit"> - <div class="row"> - <div class="col-12"> - <h3 class="mt-0" id="qa-report">Include Project Packages</h3> - <div class="form-check form-check-inline" style="text-overflow: ellipsis;overflow: hidden; width: 100%;"> - <input - type="checkbox" - id="include-packages" - name="include-packages" - value="true" - checked?={ preferences.IncludeProjectPackages } - /> - <label class="form-check-label ml-1" for="include-packages" style="overflow:hidden;text-overflow: ellipsis;" title="">Include packages of projects the maintainer is part of</label> - </div> - <i>If this option is enabled, all packages, QA reports, pull requests and bugs of projects a maintainer is part of will be displayed as well on the maintainer page. That is, if <i>Larry</i> is part of the <i>Python</i> project, all packages, QA reports, pull requests and bugs of the Python project will be displayed as well on the maintainer page of <i>Larry</i>.<br/>Below you can furthermore specify projects that will be excluded on the maintainer page. E.g. if Larry is furthermore part of the proxy-maintainers project, and the project is marked below, packages of the proxy maintainers project won't be shown on Larry's maintainer page.</i> - </div> - <div class="col-12"> - <h3 class="mt-4 pt-3" id="qa-report">Excluded Projects</h3> - </div> - for _, projects := range splitAllProjects() { - <div class="col-3"> - for _, project := range projects { - <li class="list-group-item"> - <div class="form-check form-check-inline" style="text-overflow: ellipsis;overflow: hidden; width: 100%;height:21px;"> - <input - type="checkbox" - id={ "excluded-projects-" + project.Email } - name="excluded-projects" - value={ project.Email } - checked?={ slices.Contains(preferences.ExcludedProjects, project.Email) } - /> - <label class="form-check-label ml-1" for={ "excluded-projects-" + project.Email } style="overflow:hidden;text-overflow: ellipsis;height:21px;" title={ project.Name }>{ project.Name }</label> - </div> - </li> - } - </div> - } - <div class="col-12 mt-4"> - <button type="submit" class="float-right btn btn-sm btn-primary">Save</button> - <a class="float-right btn btn-sm btn-outline-danger mr-2" href="/user/preferences/maintainers/reset">Reset to Defaults</a> - </div> - </div> - </form> -} - -func Maintainers(w http.ResponseWriter, r *http.Request) { - userPreferences := utils.GetUserPreferences(r) - r.ParseForm() - // excluded projects - excludedProjects := r.Form["excluded-projects"] - userPreferences.Maintainers.ExcludedProjects = excludedProjects - // include projects? - includePackages := r.Form.Get("include-packages") - userPreferences.Maintainers.IncludeProjectPackages = includePackages == "true" - // store cookie - encodedUserPreferences, err := json.Marshal(&userPreferences.Maintainers) - if err == nil { - sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences) - addCookie(w, "userpref_maintainers", "/", sEnc, 365*24*time.Hour) - } - http.Redirect(w, r, "/user/preferences/maintainers", http.StatusSeeOther) -} - -func ResetMaintainers(w http.ResponseWriter, r *http.Request) { - userPreferences := utils.GetDefaultUserPreferences() - encodedUserPreferences, err := json.Marshal(&userPreferences.Maintainers) - if err == nil { - sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences) - addCookie(w, "userpref_maintainers", "/", sEnc, 365*24*time.Hour) - } - http.Redirect(w, r, "/user/preferences/maintainers", http.StatusSeeOther) -} diff --git a/pkg/app/handler/user/preferences.templ b/pkg/app/handler/user/preferences.templ deleted file mode 100644 index 0eb7e4a..0000000 --- a/pkg/app/handler/user/preferences.templ +++ /dev/null @@ -1,50 +0,0 @@ -package user - -import ( - "net/http" - "soko/pkg/app/layout" - "soko/pkg/app/utils" - "soko/pkg/config" - "soko/pkg/models" - "time" -) - -var viewTabs = []layout.SubTab{ - { - Name: "Maintainers", - Link: "/user/preferences/maintainers", - Icon: "fa fa-users mr-1", - }, -} - -templ show(currentSubTab string, preferences models.UserPreferences) { - <div class="container mb-5"> - switch currentSubTab { - case "Maintainers": - @maintainers(preferences.Maintainers) - } - </div> - <script src="/assets/userpref.js"></script> -} - -func Preferences(currentSubTab string) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - layout.TabbedLayout("User", layout.About, "Preferences", "fa fa-fw fa-cog", "You can customize the page contents to your needs here", viewTabs, - currentSubTab, show(currentSubTab, utils.GetUserPreferences(r))).Render(r.Context(), w) - } -} - -// addCookie will apply a new cookie to the response of a http request -// with the key/value specified. -func addCookie(w http.ResponseWriter, name, path, value string, ttl time.Duration) { - expire := time.Now().Add(ttl) - cookie := http.Cookie{ - Name: name, - Path: path, - Value: value, - Expires: expire, - HttpOnly: true, - Secure: config.DevMode() == "false", - } - http.SetCookie(w, &cookie) -} diff --git a/pkg/app/serve.go b/pkg/app/serve.go index 1b54af7..c337dd8 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -17,7 +17,6 @@ import ( "soko/pkg/app/handler/maintainer" "soko/pkg/app/handler/packages" "soko/pkg/app/handler/useflags" - "soko/pkg/app/handler/user" "soko/pkg/config" "soko/pkg/database" @@ -111,13 +110,6 @@ func Serve() { redirect("GET /packages/stabilized.atom", "/packages/stable.atom") setRoute("GET /packages/search.atom", packages.SearchFeed) - redirect("GET /user", "/user/preferences/general") - redirect("GET /user/preferences", "/user/preferences/general") - setRoute("GET /user/preferences/maintainers", user.Preferences("Maintainers")) - - setRoute("/user/preferences/maintainers/edit", user.Maintainers) - setRoute("/user/preferences/maintainers/reset", user.ResetMaintainers) - fs := http.StripPrefix("/assets/", http.FileServer(http.Dir("/go/src/soko/assets"))) http.Handle("/assets/", fs) diff --git a/pkg/app/utils/userdata.go b/pkg/app/utils/userdata.go deleted file mode 100644 index 20624e0..0000000 --- a/pkg/app/utils/userdata.go +++ /dev/null @@ -1,26 +0,0 @@ -package utils - -import ( - b64 "encoding/base64" - "encoding/json" - "net/http" - "soko/pkg/models" -) - -func GetDefaultUserPreferences() models.UserPreferences { - return models.GetDefaultUserPreferences() -} - -func GetUserPreferences(r *http.Request) models.UserPreferences { - userPreferences := models.GetDefaultUserPreferences() - - cookie, err := r.Cookie("userpref_maintainers") - if err == nil { - cookieValue, err := b64.StdEncoding.DecodeString(cookie.Value) - if err == nil { - json.Unmarshal(cookieValue, &userPreferences.Maintainers) - } - } - - return userPreferences -} diff --git a/pkg/models/userpreferences.go b/pkg/models/userpreferences.go index 773b8eb..5426659 100644 --- a/pkg/models/userpreferences.go +++ b/pkg/models/userpreferences.go @@ -1,26 +1,5 @@ -// Contains the model of a package version - package models -type UserPreferences struct { - Maintainers MaintainersPreferences -} - -type MaintainersPreferences struct { - IncludeProjectPackages bool - ExcludedProjects []string -} - var ArchesToShow = [...]string{"amd64", "x86", "alpha", "arm", "arm64", "hppa", "ia64", "ppc", "ppc64", "riscv", "sparc"} var AllArches = [...]string{"alpha", "amd64", "arm", "arm64", "hppa", "ia64", "mips", "ppc", "ppc64", "riscv", "s390", "sparc", "x86"} -var OldCookieNames = [...]string{"search_history", "userpref_general", "userpref_packages", "userpref_useflags", "userpref_arches"} - -func GetDefaultUserPreferences() UserPreferences { - userPreferences := UserPreferences{} - userPreferences.Maintainers = MaintainersPreferences{} - - userPreferences.Maintainers.IncludeProjectPackages = false - userPreferences.Maintainers.ExcludedProjects = []string{} - - return userPreferences -} +var OldCookieNames = [...]string{"search_history", "userpref_general", "userpref_packages", "userpref_maintainers", "userpref_useflags", "userpref_arches"} |