summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-01-03 21:02:24 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-01-03 21:02:24 +0000
commitac9118638a6513d12cd0780f1846ff65a0d698a1 (patch)
tree9676d565290110207eab8970769fd3130e61a90f
parentIntroduce to mock mail server (diff)
downloadgentoobrowse-api-ac9118638a6513d12cd0780f1846ff65a0d698a1.tar.bz2
gentoobrowse-api-ac9118638a6513d12cd0780f1846ff65a0d698a1.tar.xz
gentoobrowse-api-ac9118638a6513d12cd0780f1846ff65a0d698a1.zip
Add fields/members/functions for storing a user's signup date and when they last received a mailshot
-rw-r--r--gentoobrowse-api/api/users.ice1
-rw-r--r--gentoobrowse-api/db/schema.sql2
-rw-r--r--gentoobrowse-api/domain/user-models.ice5
-rw-r--r--gentoobrowse-api/service/sql/users/authenticate.sql2
-rw-r--r--gentoobrowse-api/service/sql/users/create.sql2
-rw-r--r--gentoobrowse-api/service/sql/users/find.sql2
-rw-r--r--gentoobrowse-api/service/sql/users/get.sql2
-rw-r--r--gentoobrowse-api/service/sql/users/mailshotsent.sql3
-rw-r--r--gentoobrowse-api/service/sql/users/verify.sql2
-rw-r--r--gentoobrowse-api/service/usersimpl.cpp10
-rw-r--r--gentoobrowse-api/service/usersimpl.h1
-rw-r--r--gentoobrowse-api/unittests/data.sql2
-rw-r--r--gentoobrowse-api/unittests/fixtures/users.dat4
-rw-r--r--gentoobrowse-api/unittests/testNotifications.cpp6
-rw-r--r--gentoobrowse-api/unittests/testUsers.cpp21
15 files changed, 54 insertions, 11 deletions
diff --git a/gentoobrowse-api/api/users.ice b/gentoobrowse-api/api/users.ice
index 16fa7e2..f9d66df 100644
--- a/gentoobrowse-api/api/users.ice
+++ b/gentoobrowse-api/api/users.ice
@@ -14,6 +14,7 @@ module Gentoo {
User get(int id) throws Slicer::NoRowsReturned;
User find(string username) throws Slicer::NoRowsReturned;
NewUser create(string username, string password, string realname, string email) throws DuplicateDetails;
+ void mailshotsent(int id);
void remove(int id, string password) throws Slicer::NoRowsReturned;
void track(int userId, int packageId);
diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql
index 3ed531c..cb74add 100644
--- a/gentoobrowse-api/db/schema.sql
+++ b/gentoobrowse-api/db/schema.sql
@@ -584,6 +584,8 @@ CREATE TABLE users (
userrealname text NOT NULL,
userpassword text NOT NULL,
useremail text NOT NULL,
+ signedup timestamp without time zone DEFAULT now() NOT NULL,
+ lastmailshot timestamp without time zone,
verifyguid uuid
);
ALTER TABLE users OWNER TO gentoo;
diff --git a/gentoobrowse-api/domain/user-models.ice b/gentoobrowse-api/domain/user-models.ice
index cf0a386..7e2d4f2 100644
--- a/gentoobrowse-api/domain/user-models.ice
+++ b/gentoobrowse-api/domain/user-models.ice
@@ -1,12 +1,17 @@
#ifndef GENTOO_USER_MODELS
#define GENTOO_USER_MODELS
+[ "slicer:include:boost/date_time/posix_time/posix_time.hpp" ]
module Gentoo {
class User {
int userid;
string username;
string userrealname;
string useremail;
+ [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ]
+ string signedup;
+ [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ]
+ optional(0) string lastmailshot;
};
class NewUser extends User {
diff --git a/gentoobrowse-api/service/sql/users/authenticate.sql b/gentoobrowse-api/service/sql/users/authenticate.sql
index 86b8cc1..0b3ac09 100644
--- a/gentoobrowse-api/service/sql/users/authenticate.sql
+++ b/gentoobrowse-api/service/sql/users/authenticate.sql
@@ -1,4 +1,4 @@
-SELECT userid, username, userrealname, useremail
+SELECT userid, username, userrealname, useremail, signedup, lastmailshot
FROM gentoobrowse.users
WHERE username = ?
AND userpassword = ?
diff --git a/gentoobrowse-api/service/sql/users/create.sql b/gentoobrowse-api/service/sql/users/create.sql
index dc43f18..e3b1b87 100644
--- a/gentoobrowse-api/service/sql/users/create.sql
+++ b/gentoobrowse-api/service/sql/users/create.sql
@@ -1,4 +1,4 @@
-- libdbpp:no-cursor
INSERT INTO gentoobrowse.users(username, userpassword, userrealname, useremail, verifyguid)
VALUES(?, ?, ?, ?, uuid_generate_v4())
-RETURNING userid, username, userrealname, useremail, verifyguid
+RETURNING userid, username, userrealname, useremail, verifyguid, signedup, lastmailshot
diff --git a/gentoobrowse-api/service/sql/users/find.sql b/gentoobrowse-api/service/sql/users/find.sql
index 026cfcf..d7d5767 100644
--- a/gentoobrowse-api/service/sql/users/find.sql
+++ b/gentoobrowse-api/service/sql/users/find.sql
@@ -1,3 +1,3 @@
-SELECT userid, username, userrealname, useremail
+SELECT userid, username, userrealname, useremail, signedup, lastmailshot
FROM gentoobrowse.users
WHERE username = ?
diff --git a/gentoobrowse-api/service/sql/users/get.sql b/gentoobrowse-api/service/sql/users/get.sql
index 7bd778e..49e8144 100644
--- a/gentoobrowse-api/service/sql/users/get.sql
+++ b/gentoobrowse-api/service/sql/users/get.sql
@@ -1,3 +1,3 @@
-SELECT userid, username, userrealname, useremail
+SELECT userid, username, userrealname, useremail, signedup, lastmailshot
FROM gentoobrowse.users
WHERE userid = ?
diff --git a/gentoobrowse-api/service/sql/users/mailshotsent.sql b/gentoobrowse-api/service/sql/users/mailshotsent.sql
new file mode 100644
index 0000000..21ef5a7
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/mailshotsent.sql
@@ -0,0 +1,3 @@
+UPDATE gentoobrowse.users SET
+ lastmailshot = NOW()
+WHERE userid = ?
diff --git a/gentoobrowse-api/service/sql/users/verify.sql b/gentoobrowse-api/service/sql/users/verify.sql
index 91a7151..825ad2c 100644
--- a/gentoobrowse-api/service/sql/users/verify.sql
+++ b/gentoobrowse-api/service/sql/users/verify.sql
@@ -3,4 +3,4 @@ UPDATE gentoobrowse.users SET
verifyguid = NULL
WHERE username = ?
AND verifyguid = ?
-RETURNING userid, username, userrealname, useremail
+RETURNING userid, username, userrealname, useremail, signedup, lastmailshot
diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp
index 67a1bd1..c2f45a7 100644
--- a/gentoobrowse-api/service/usersimpl.cpp
+++ b/gentoobrowse-api/service/usersimpl.cpp
@@ -9,6 +9,7 @@
#include <sql/users/track.sql.h>
#include <sql/users/untrack.sql.h>
#include <sql/users/tracked.sql.h>
+#include <sql/users/mailshotsent.sql.h>
namespace Gentoo {
namespace Service {
@@ -48,6 +49,15 @@ Users::create(const std::string & username, const std::string & password, const
}
void
+Users::mailshotsent(Ice::Int id, const Ice::Current &)
+{
+ auto dbc = db->get();
+ auto upd = sql::users::mailshotsent.modify(dbc.get());
+ upd->bindParamI(0, id);
+ upd->execute();
+}
+
+void
Users::remove(Ice::Int id, const std::string & password, const Ice::Current &)
{
auto dbc = db->get();
diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h
index ae342a9..84cf970 100644
--- a/gentoobrowse-api/service/usersimpl.h
+++ b/gentoobrowse-api/service/usersimpl.h
@@ -17,6 +17,7 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC
Gentoo::UserPtr get(Ice::Int id, const Ice::Current &) override;
Gentoo::UserPtr find(const std::string & username, const Ice::Current &) override;
Gentoo::NewUserPtr create(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override;
+ void mailshotsent(Ice::Int id, const Ice::Current &) override;
void remove(Ice::Int id, const std::string &, const Ice::Current &) override;
void track(Ice::Int, Ice::Int, const Ice::Current &) override;
diff --git a/gentoobrowse-api/unittests/data.sql b/gentoobrowse-api/unittests/data.sql
index d1b70de..aedf5c6 100644
--- a/gentoobrowse-api/unittests/data.sql
+++ b/gentoobrowse-api/unittests/data.sql
@@ -26,7 +26,7 @@ COPY gentoobrowse.use_global (use, description) FROM '$SCRIPTDIR/fixtures/use_gl
COPY gentoobrowse.use_groups (usegroupid, name) FROM '$SCRIPTDIR/fixtures/use_groups.dat';
COPY gentoobrowse.use_group (usegroupid, use, description) FROM '$SCRIPTDIR/fixtures/use_group.dat';
COPY gentoobrowse.use_local (packageid, use, description) FROM '$SCRIPTDIR/fixtures/use_local.dat';
-COPY gentoobrowse.users (userid, username, userrealname, userpassword, useremail, verifyguid) FROM '$SCRIPTDIR/fixtures/users.dat';
+COPY gentoobrowse.users (userid, username, userrealname, userpassword, useremail, verifyguid, lastmailshot, signedup) FROM '$SCRIPTDIR/fixtures/users.dat';
COPY gentoobrowse.user_ebuild_emails (userid, ebuildid, sentat) FROM '$SCRIPTDIR/fixtures/user_ebuild_emails.dat';
COPY gentoobrowse.user_packages (userid, packageid, trackedsince) FROM '$SCRIPTDIR/fixtures/user_packages.dat';
COPY gentoobrowse.changelog (changeid, repoid, commitid, committime, authorname, authoremail, summary, body, files) FROM '$SCRIPTDIR/fixtures/changelog.dat';
diff --git a/gentoobrowse-api/unittests/fixtures/users.dat b/gentoobrowse-api/unittests/fixtures/users.dat
index a1f60e5..cbc63fb 100644
--- a/gentoobrowse-api/unittests/fixtures/users.dat
+++ b/gentoobrowse-api/unittests/fixtures/users.dat
@@ -1,2 +1,2 @@
-1 randomdan Dan Goodliffe p@55w0rd dan@randomdan.homeip.net \N
-2 unverified Dan Goodliffe p@55w0rd something@randomdan.homeip.net a24eb4fa-8a42-11e6-a04e-c86000a60e12
+1 randomdan Dan Goodliffe p@55w0rd dan@randomdan.homeip.net \N \N 2015-10-01T12:13:14
+2 unverified Dan Goodliffe p@55w0rd something@randomdan.homeip.net a24eb4fa-8a42-11e6-a04e-c86000a60e12 \N 2015-10-01T12:13:14
diff --git a/gentoobrowse-api/unittests/testNotifications.cpp b/gentoobrowse-api/unittests/testNotifications.cpp
index 21a76a5..15d62ea 100644
--- a/gentoobrowse-api/unittests/testNotifications.cpp
+++ b/gentoobrowse-api/unittests/testNotifications.cpp
@@ -41,7 +41,7 @@ commonAssert(Gentoo::EmailPtr e)
BOOST_AUTO_TEST_CASE( testSend )
{
- Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "noone@randomdan.homeip.net", "some-guid");
+ Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "noone@randomdan.homeip.net", "2017-10-01T12:34:56", IceUtil::None, "some-guid");
auto e = n->getSignup(u);
BOOST_REQUIRE(e);
ms->sendEmail(e);
@@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE( testSend )
BOOST_AUTO_TEST_CASE( testSignup )
{
- Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "test@user.com", "some-guid");
+ Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None, "some-guid");
auto e = n->getSignup(u);
BOOST_REQUIRE(e);
BOOST_REQUIRE_EQUAL(e->subject, "Gentoo Browse: Welcome");
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE( testSignup )
BOOST_AUTO_TEST_CASE( testNews )
{
- Gentoo::UserPtr u = new Gentoo::User(1, "testuser", "Test User", "test@user.com");
+ Gentoo::UserPtr u = new Gentoo::User(1, "testuser", "Test User", "test@user.com", "2017-10-01T12:34:56", IceUtil::None);
Gentoo::NewsContent nc {
{
new Gentoo::Category(1, "app-test", "Test cat1"),
diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp
index a4567f3..e515b77 100644
--- a/gentoobrowse-api/unittests/testUsers.cpp
+++ b/gentoobrowse-api/unittests/testUsers.cpp
@@ -48,6 +48,8 @@ BOOST_AUTO_TEST_CASE( create )
BOOST_REQUIRE_EQUAL("testuser", user->username);
BOOST_REQUIRE_EQUAL("Test User", user->userrealname);
BOOST_REQUIRE_EQUAL("test@user.com", user->useremail);
+ BOOST_REQUIRE(user->signedup.length() > 19);
+ BOOST_REQUIRE(!user->lastmailshot);
BOOST_REQUIRE_EQUAL(36, user->verifyguid.length());
auto verified = u->verify(user->username, user->verifyguid);
BOOST_REQUIRE(verified);
@@ -60,6 +62,25 @@ BOOST_AUTO_TEST_CASE( get )
BOOST_REQUIRE_EQUAL("testuser", user->username);
BOOST_REQUIRE_EQUAL("Test User", user->userrealname);
BOOST_REQUIRE_EQUAL("test@user.com", user->useremail);
+ BOOST_REQUIRE(user->signedup.length() > 19);
+ BOOST_REQUIRE(!user->lastmailshot);
+}
+
+BOOST_AUTO_TEST_CASE( sendmailshot )
+{
+ auto user = u->get(3);
+ BOOST_REQUIRE(user);
+ BOOST_REQUIRE(!user->lastmailshot);
+ u->mailshotsent(3);
+ user = u->get(3);
+ BOOST_REQUIRE(user);
+ BOOST_REQUIRE_EQUAL(3, user->userid);
+ BOOST_REQUIRE_EQUAL("testuser", user->username);
+ BOOST_REQUIRE_EQUAL("Test User", user->userrealname);
+ BOOST_REQUIRE_EQUAL("test@user.com", user->useremail);
+ BOOST_REQUIRE(user->signedup.length() > 19);
+ BOOST_REQUIRE(user->lastmailshot);
+ BOOST_REQUIRE(user->lastmailshot->length() > 19);
}
BOOST_AUTO_TEST_CASE( getMissing )