(app *App, w http.ResponseWriter, r *http.Request)
| 216 | } |
| 217 | |
| 218 | func handleDeleteEmailSubscription(app *App, w http.ResponseWriter, r *http.Request) error { |
| 219 | alias := collectionAliasFromReq(r) |
| 220 | |
| 221 | vars := mux.Vars(r) |
| 222 | subID := vars["subscriber"] |
| 223 | email := r.FormValue("email") |
| 224 | token := r.FormValue("t") |
| 225 | slug := r.FormValue("slug") |
| 226 | isWeb := r.Method == "GET" |
| 227 | |
| 228 | // Display collection if this is a collection |
| 229 | var c *Collection |
| 230 | var err error |
| 231 | if app.cfg.App.SingleUser { |
| 232 | c, err = app.db.GetCollectionByID(1) |
| 233 | } else { |
| 234 | c, err = app.db.GetCollection(alias) |
| 235 | } |
| 236 | if err != nil { |
| 237 | log.Error("Get collection: %s", err) |
| 238 | return err |
| 239 | } |
| 240 | |
| 241 | from := c.CanonicalURL() |
| 242 | |
| 243 | if subID != "" { |
| 244 | // User unsubscribing via email, so assume action is taken by either current |
| 245 | // user or not current user, and only use the request's information to |
| 246 | // satisfy this unsubscribe, i.e. subscriberID and token. |
| 247 | err = app.db.DeleteEmailSubscriber(subID, token) |
| 248 | } else { |
| 249 | // User unsubscribing through the web app, so assume action is taken by |
| 250 | // currently-auth'd user. |
| 251 | var userID int64 |
| 252 | u := getUserSession(app, r) |
| 253 | if u != nil { |
| 254 | // User is logged in |
| 255 | userID = u.ID |
| 256 | if userID == c.OwnerID { |
| 257 | from = "/" + c.Alias + "/" |
| 258 | } |
| 259 | } |
| 260 | if email == "" && userID <= 0 { |
| 261 | // Get email address from saved cookie |
| 262 | session, err := app.sessionStore.Get(r, userEmailCookieName) |
| 263 | if err != nil { |
| 264 | log.Error("Unable to get email cookie: %s", err) |
| 265 | } else { |
| 266 | email = session.Values[userEmailCookieVal].(string) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | if email == "" && userID <= 0 { |
| 271 | err = fmt.Errorf("No subscriber given.") |
| 272 | log.Error("Not deleting subscription: %s", err) |
| 273 | return err |
| 274 | } |
| 275 |
nothing calls this directly
no test coverage detected