Delete ask sindominante functionallity

merge-requests/11/head
meskio 3 years ago
parent b25891d517
commit d1f8e4fcc9
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 17
      db/askSindominante.go
  2. 2
      db/db.go
  3. 28
      main.go
  4. 25
      server/server.go
  5. 43
      server/user.go
  6. 26
      tmpl/index.html

@ -1,17 +0,0 @@
package db
var (
askSindominanteBucket = []byte("ask-sindominante")
)
// HasBeingAskedForSindominante checks if the user has being already asked for sindominante
func (db *DB) HasBeingAskedForSindominante(user string) bool {
var answer string
err := db.get(askSindominanteBucket, user, &answer)
return err == nil
}
// AnswerForSindominante register the answer for sindominante for user
func (db *DB) AnswerForSindominante(user string, answer string) error {
return db.put(askSindominanteBucket, user, answer)
}

@ -21,7 +21,7 @@ func Init(path string) (*DB, error) {
}
err = bolt.Update(func(tx *bbolt.Tx) error {
for _, bucket := range [][]byte{askSindominanteBucket, inviteBucket, accountBucket} {
for _, bucket := range [][]byte{inviteBucket, accountBucket} {
_, err := tx.CreateBucketIfNotExists(bucket)
if err != nil {

@ -23,17 +23,16 @@ var (
func main() {
var (
ldapaddr = flag.String("ldapaddr", "localhost:389", "LDAP server address and port")
domain = flag.String("domain", "", "LDAP domain components")
ldappass = flag.String("ldappass", "", "Password of the LDAP `admin' user")
homepath = flag.String("homepath", "/home/", "Path to the user homes")
smtpaddr = flag.String("smtpaddr", "localhost:25", "The address of the smtp server to send email")
email = flag.String("email", "", "The email address to send notifications from")
emailpass = flag.String("emailpass", "", "The password of the email address")
httpaddr = flag.String("httpaddr", ":8080", "Web server address and port")
dbpath = flag.String("dbpath", "bolt.db", "The path to store the lowry status database")
ro = flag.Bool("ro", false, "Read-Only mode")
askRolePath = flag.String("ask-role-list", "", "List of usernames to ask if want to be sindominantes")
ldapaddr = flag.String("ldapaddr", "localhost:389", "LDAP server address and port")
domain = flag.String("domain", "", "LDAP domain components")
ldappass = flag.String("ldappass", "", "Password of the LDAP `admin' user")
homepath = flag.String("homepath", "/home/", "Path to the user homes")
smtpaddr = flag.String("smtpaddr", "localhost:25", "The address of the smtp server to send email")
email = flag.String("email", "", "The email address to send notifications from")
emailpass = flag.String("emailpass", "", "The password of the email address")
httpaddr = flag.String("httpaddr", ":8080", "Web server address and port")
dbpath = flag.String("dbpath", "bolt.db", "The path to store the lowry status database")
ro = flag.Bool("ro", false, "Read-Only mode")
)
flag.String(flag.DefaultConfigFlagname, "/etc/lowry.conf", "Path to configuration file")
flag.Parse()
@ -59,12 +58,7 @@ func main() {
defer ldb.Close()
go cleanInvites(ldb)
usersAskRole := []string{}
if *askRolePath != "" {
usersAskRole = readUserList(*askRolePath)
}
log.Fatal(server.Serve(*httpaddr, &l, m, ldb, usersAskRole))
log.Fatal(server.Serve(*httpaddr, &l, m, ldb))
}
func lockUsers(l ldap.Ldap) {

@ -11,23 +11,21 @@ import (
)
type server struct {
ldap *ldap.Ldap
mail *mail.Mail
db *db.DB
sess *sessionStore
tmpl *template.Template
usersAskRole []string
ldap *ldap.Ldap
mail *mail.Mail
db *db.DB
sess *sessionStore
tmpl *template.Template
}
// Serve lowry web site
func Serve(addr string, l *ldap.Ldap, m *mail.Mail, ldb *db.DB, usersAskRole []string) error {
func Serve(addr string, l *ldap.Ldap, m *mail.Mail, ldb *db.DB) error {
s := server{
ldap: l,
mail: m,
db: ldb,
sess: initSessionStore(),
tmpl: initTemplate(),
usersAskRole: usersAskRole,
ldap: l,
mail: m,
db: ldb,
sess: initSessionStore(),
tmpl: initTemplate(),
}
r := mux.NewRouter()
@ -52,7 +50,6 @@ func Serve(addr string, l *ldap.Ldap, m *mail.Mail, ldb *db.DB, usersAskRole []s
r.HandleFunc("/groups/{name}", s.groupHandler)
r.HandleFunc("/groups/{name}/add/", s.addUserGroupHandler).Methods("POST")
r.HandleFunc("/groups/{name}/del/", s.delUserGroupHandler).Methods("POST")
r.HandleFunc("/ask-sindominante/", s.askSindominante).Methods("POST")
r.HandleFunc("/bundle.js", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "dist/bundle.js") })
r.HandleFunc("/style.css", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "dist/style.css") })

@ -1,10 +1,7 @@
package server
import (
"log"
"net/http"
"0xacab.org/sindominio/lowry/ldap"
)
func (s *server) homeHandler(w http.ResponseWriter, r *http.Request) {
@ -15,12 +12,10 @@ func (s *server) homeHandler(w http.ResponseWriter, r *http.Request) {
return
}
askSindominante := s.needsToAskForSindominante(response.User)
needPasswordChange := !s.ldap.IsUserPassUptodate(response.User)
data := struct {
AskSindominante bool
NeedPasswordChange bool
}{askSindominante, needPasswordChange}
}{needPasswordChange}
response.execute(data)
}
@ -77,39 +72,3 @@ func (s *server) passwordHandler(w http.ResponseWriter, r *http.Request) {
response.execute("PassChanged")
}
}
func (s *server) askSindominante(w http.ResponseWriter, r *http.Request) {
role := r.FormValue("role")
response := s.newResponse("", w, r)
if !s.userInAskList(response.User) {
log.Printf("An attempt to set role without being in the list: %s - %s", response.User, role)
s.forbiddenHandler(w, r)
return
}
err := s.ldap.ChangeRole(response.User, ldap.RoleFromString(role))
if err != nil {
log.Printf("An error has ocurred setting the role: %v", err)
} else {
s.db.AnswerForSindominante(response.User, role)
}
http.Redirect(w, r, "/", http.StatusFound)
}
func (s *server) needsToAskForSindominante(user string) bool {
if !s.userInAskList(user) {
return false
}
return !s.db.HasBeingAskedForSindominante(user)
}
func (s *server) userInAskList(user string) bool {
for _, u := range s.usersAskRole {
if u == user {
return true
}
}
return false
}

@ -5,31 +5,6 @@
<div class="container">
{{if .Data.AskSindominante}}
<br />
<div class="row col-md">
<p>Como habrás visto SinDominio está en <a href="https://wp.sindominio.net/a-por-otras-dos-decadas-libres-de-dominio/">proceso de cambios</a>. ¿Cual quieres que sea tu relación con SinDominio?</p>
<form action="/ask-sindominante/" method="post">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="role" id="sindominante" value="sindominante" checked>
<dt>Sindominante</dt><dd>Seguirás formando parte de las decisiones del día a día en la asamblea, manteniendo SinDominio funcionando y tendrás acceso a todos los servicios de SinDominio.</dd>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="role" id="amiga" value="amiga">
<dt>Amiga</dt><dd>Pasarás a ser una cuenta usuaria de SinDominio sin acceso a la toma de decisiones del proyecto pero con correo electrónico y mensajería instantánea. Si ya tienes pagina web u otros servicios estos se respetarán.</dd>
</label>
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</form>
</div>
{{else}}
{{if .Data.NeedPasswordChange}}
<br />
@ -79,7 +54,6 @@
</div>
</div>
{{end}}
{{end}}
</div>
{{template "load-password.js"}}

Loading…
Cancel
Save