Finish mail settings

This commit is contained in:
Eike Kettner
2020-01-07 00:20:28 +01:00
parent f235f3a030
commit 32050a9faf
11 changed files with 391 additions and 57 deletions

View File

@ -3,9 +3,9 @@ CREATE TABLE "useremail" (
"uid" varchar(254) not null,
"name" varchar(254) not null,
"smtp_host" varchar(254) not null,
"smtp_port" int not null,
"smtp_user" varchar(254) not null,
"smtp_password" varchar(254) not null,
"smtp_port" int,
"smtp_user" varchar(254),
"smtp_password" varchar(254),
"smtp_ssl" varchar(254) not null,
"smtp_certcheck" boolean not null,
"mail_from" varchar(254) not null,

View File

@ -57,7 +57,7 @@ object RUserEmail {
now
)
def apply(
def fromAccount(
accId: AccountId,
name: Ident,
smtpHost: String,
@ -130,17 +130,21 @@ object RUserEmail {
).update.run
def update(eId: Ident, v: RUserEmail): ConnectionIO[Int] =
updateRow(table, id.is(eId), commas(
name.setTo(v.name),
smtpHost.setTo(v.smtpHost),
smtpPort.setTo(v.smtpPort),
smtpUser.setTo(v.smtpUser),
smtpPass.setTo(v.smtpPassword),
smtpSsl.setTo(v.smtpSsl),
smtpCertCheck.setTo(v.smtpCertCheck),
mailFrom.setTo(v.mailFrom),
mailReplyTo.setTo(v.mailReplyTo)
)).update.run
updateRow(
table,
id.is(eId),
commas(
name.setTo(v.name),
smtpHost.setTo(v.smtpHost),
smtpPort.setTo(v.smtpPort),
smtpUser.setTo(v.smtpUser),
smtpPass.setTo(v.smtpPassword),
smtpSsl.setTo(v.smtpSsl),
smtpCertCheck.setTo(v.smtpCertCheck),
mailFrom.setTo(v.mailFrom),
mailReplyTo.setTo(v.mailReplyTo)
)
).update.run
def findByUser(userId: Ident): ConnectionIO[Vector[RUserEmail]] =
selectSimple(all, table, uid.is(userId)).query[RUserEmail].to[Vector]
@ -162,7 +166,7 @@ object RUserEmail {
case None => Seq.empty
})
selectSimple(all, from, and(cond)).query[RUserEmail]
(selectSimple(all.map(_.prefix("m")), from, and(cond)) ++ orderBy(mName.f)).query[RUserEmail]
}
def findByAccount(
@ -174,6 +178,20 @@ object RUserEmail {
def getByName(accId: AccountId, name: Ident): ConnectionIO[Option[RUserEmail]] =
findByAccount0(accId, Some(name.id), true).option
def delete(accId: AccountId, connName: Ident): ConnectionIO[Int] = {
val uId = RUser.Columns.uid
val uColl = RUser.Columns.cid
val uLogin = RUser.Columns.login
val cond = Seq(uColl.is(accId.collective), uLogin.is(accId.user))
deleteFrom(
table,
fr"uid in (" ++ selectSimple(Seq(uId), RUser.table, and(cond)) ++ fr") AND" ++ name.is(
connName
)
).update.run
}
def exists(accId: AccountId, name: Ident): ConnectionIO[Boolean] =
getByName(accId, name).map(_.isDefined)