summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-10-17 19:41:29 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-10-17 19:41:29 +0100
commitaf0d8487354cf3e22d677b319e5f8e9b57a745ed (patch)
treef87bc6f8fa98b3cc8f87916ae7239aed915deba8
parentReplace bespoke parser for masks with an AdHoc Lexer (diff)
downloadgentoobrowse-api-af0d8487354cf3e22d677b319e5f8e9b57a745ed.tar.bz2
gentoobrowse-api-af0d8487354cf3e22d677b319e5f8e9b57a745ed.tar.xz
gentoobrowse-api-af0d8487354cf3e22d677b319e5f8e9b57a745ed.zip
Add all the expected methods to the user service
-rw-r--r--gentoobrowse-api/api/users.ice8
-rw-r--r--gentoobrowse-api/db/schema.sql3
-rw-r--r--gentoobrowse-api/domain/user-models.ice5
-rw-r--r--gentoobrowse-api/service/sql/users/create.sql4
-rw-r--r--gentoobrowse-api/service/sql/users/find.sql3
-rw-r--r--gentoobrowse-api/service/sql/users/get.sql3
-rw-r--r--gentoobrowse-api/service/sql/users/safeDelete.sql3
-rw-r--r--gentoobrowse-api/service/sql/users/track.sql2
-rw-r--r--gentoobrowse-api/service/sql/users/untrack.sql3
-rw-r--r--gentoobrowse-api/service/usersimpl.cpp54
-rw-r--r--gentoobrowse-api/service/usersimpl.h8
-rw-r--r--gentoobrowse-api/unittests/testUsers.cpp59
12 files changed, 154 insertions, 1 deletions
diff --git a/gentoobrowse-api/api/users.ice b/gentoobrowse-api/api/users.ice
index 798ab52..d0c37f7 100644
--- a/gentoobrowse-api/api/users.ice
+++ b/gentoobrowse-api/api/users.ice
@@ -8,6 +8,14 @@ module Gentoo {
interface Users {
User authenticate(string username, string password) throws Slicer::NoRowsReturned;
User verify(string username, string verifyguid) throws Slicer::NoRowsReturned;
+
+ 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 remove(int id, string password) throws Slicer::NoRowsReturned;
+
+ void track(int userId, int packageId);
+ void untrack(int userId, int packageId);
};
};
diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql
index 8951297..d5d7678 100644
--- a/gentoobrowse-api/db/schema.sql
+++ b/gentoobrowse-api/db/schema.sql
@@ -5,6 +5,7 @@ SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = true;
SET client_min_messages = warning;
+CREATE EXTENSION "uuid-ossp";
-- Name: gentoobrowse; Type: SCHEMA; Schema: -; Owner: gentoo
CREATE SCHEMA gentoobrowse;
ALTER SCHEMA gentoobrowse OWNER TO gentoo;
@@ -603,7 +604,7 @@ ALTER TABLE users OWNER TO gentoo;
COMMENT ON TABLE users IS 'Registered users';
-- Name: users_userid_seq; Type: SEQUENCE; Schema: gentoobrowse; Owner: gentoo
CREATE SEQUENCE users_userid_seq
- START WITH 1
+ START WITH 3
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
diff --git a/gentoobrowse-api/domain/user-models.ice b/gentoobrowse-api/domain/user-models.ice
index ccbda99..cf0a386 100644
--- a/gentoobrowse-api/domain/user-models.ice
+++ b/gentoobrowse-api/domain/user-models.ice
@@ -9,7 +9,12 @@ module Gentoo {
string useremail;
};
+ class NewUser extends User {
+ string verifyguid;
+ };
+
exception InvalidCredentials { };
+ exception DuplicateDetails { };
};
#endif
diff --git a/gentoobrowse-api/service/sql/users/create.sql b/gentoobrowse-api/service/sql/users/create.sql
new file mode 100644
index 0000000..dc43f18
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/create.sql
@@ -0,0 +1,4 @@
+-- libdbpp:no-cursor
+INSERT INTO gentoobrowse.users(username, userpassword, userrealname, useremail, verifyguid)
+VALUES(?, ?, ?, ?, uuid_generate_v4())
+RETURNING userid, username, userrealname, useremail, verifyguid
diff --git a/gentoobrowse-api/service/sql/users/find.sql b/gentoobrowse-api/service/sql/users/find.sql
new file mode 100644
index 0000000..026cfcf
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/find.sql
@@ -0,0 +1,3 @@
+SELECT userid, username, userrealname, useremail
+FROM gentoobrowse.users
+WHERE username = ?
diff --git a/gentoobrowse-api/service/sql/users/get.sql b/gentoobrowse-api/service/sql/users/get.sql
new file mode 100644
index 0000000..7bd778e
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/get.sql
@@ -0,0 +1,3 @@
+SELECT userid, username, userrealname, useremail
+FROM gentoobrowse.users
+WHERE userid = ?
diff --git a/gentoobrowse-api/service/sql/users/safeDelete.sql b/gentoobrowse-api/service/sql/users/safeDelete.sql
new file mode 100644
index 0000000..198c534
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/safeDelete.sql
@@ -0,0 +1,3 @@
+DELETE FROM gentoobrowse.users
+WHERE userid = ?
+AND userpassword = ?
diff --git a/gentoobrowse-api/service/sql/users/track.sql b/gentoobrowse-api/service/sql/users/track.sql
new file mode 100644
index 0000000..c05c6df
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/track.sql
@@ -0,0 +1,2 @@
+INSERT INTO gentoobrowse.user_packages(userid, packageid)
+VALUES(?, ?)
diff --git a/gentoobrowse-api/service/sql/users/untrack.sql b/gentoobrowse-api/service/sql/users/untrack.sql
new file mode 100644
index 0000000..e303ec1
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/untrack.sql
@@ -0,0 +1,3 @@
+DELETE FROM gentoobrowse.user_packages
+WHERE userid = ?
+AND packageid = ?
diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp
index dc3769b..6aee42d 100644
--- a/gentoobrowse-api/service/usersimpl.cpp
+++ b/gentoobrowse-api/service/usersimpl.cpp
@@ -2,6 +2,12 @@
#include <modifycommand.h>
#include <sql/users/authenticate.sql.h>
#include <sql/users/verify.sql.h>
+#include <sql/users/create.sql.h>
+#include <sql/users/get.sql.h>
+#include <sql/users/find.sql.h>
+#include <sql/users/safeDelete.sql.h>
+#include <sql/users/track.sql.h>
+#include <sql/users/untrack.sql.h>
namespace Gentoo {
namespace Service {
@@ -21,6 +27,54 @@ Users::verify(const std::string & username, const std::string & verifyguid, cons
{
return fetch<Gentoo::UserPtr>(sql::users::verify, username, verifyguid);
}
+
+Gentoo::UserPtr
+Users::get(Ice::Int id, const Ice::Current &)
+{
+ return fetch<Gentoo::UserPtr>(sql::users::get, id);
+}
+
+Gentoo::UserPtr
+Users::find(const std::string & username, const Ice::Current &)
+{
+ return fetch<Gentoo::UserPtr>(sql::users::find, username);
+}
+
+Gentoo::NewUserPtr
+Users::create(const std::string & username, const std::string & password, const std::string & realname, const std::string & email, const Ice::Current &)
+{
+ return fetch<Gentoo::NewUserPtr>(sql::users::create, username, password, realname, email);
+}
+
+void
+Users::remove(Ice::Int id, const std::string & password, const Ice::Current &)
+{
+ auto dbc = db->get();
+ auto del = dbc->modify(sql::users::safeDelete.getSql());
+ del->bindParamI(0, id);
+ del->bindParamS(1, password);
+ del->execute();
+}
+
+void
+Users::track(Ice::Int userId, Ice::Int packageId, const Ice::Current &)
+{
+ auto dbc = db->get();
+ auto track = dbc->modify(sql::users::track.getSql());
+ track->bindParamI(0, userId);
+ track->bindParamI(1, packageId);
+ track->execute();
+}
+
+void
+Users::untrack(Ice::Int userId, Ice::Int packageId, const Ice::Current &)
+{
+ auto dbc = db->get();
+ auto untrack = dbc->modify(sql::users::untrack.getSql());
+ untrack->bindParamI(0, userId);
+ untrack->bindParamI(1, packageId);
+ untrack->execute();
+}
}
}
diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h
index 76a6ade..f97e2ad 100644
--- a/gentoobrowse-api/service/usersimpl.h
+++ b/gentoobrowse-api/service/usersimpl.h
@@ -13,6 +13,14 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC
Gentoo::UserPtr authenticate(const std::string &, const std::string &, const Ice::Current &) override;
Gentoo::UserPtr verify(const std::string &, const std::string &, const Ice::Current &) override;
+
+ 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 remove(Ice::Int id, const std::string &, const Ice::Current &) override;
+
+ void track(Ice::Int, Ice::Int, const Ice::Current &) override;
+ void untrack(Ice::Int, Ice::Int, const Ice::Current &) override;
};
}
}
diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp
index 93c8fdd..e4c1ac4 100644
--- a/gentoobrowse-api/unittests/testUsers.cpp
+++ b/gentoobrowse-api/unittests/testUsers.cpp
@@ -41,5 +41,64 @@ BOOST_AUTO_TEST_CASE( authenticateVerify )
BOOST_REQUIRE_THROW(u->verify("unverified", "a24eb4fa-8a42-11e6-a04e-c86000a60e12"), Slicer::NoRowsReturned);
}
+BOOST_AUTO_TEST_CASE( create )
+{
+ auto user = u->create("testuser", "testpass", "Test User", "test@user.com");
+ 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_EQUAL(36, user->verifyguid.length());
+ auto verified = u->verify(user->username, user->verifyguid);
+ BOOST_REQUIRE(verified);
+}
+
+BOOST_AUTO_TEST_CASE( get )
+{
+ auto user = u->get(3);
+ 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_AUTO_TEST_CASE( getMissing )
+{
+ BOOST_REQUIRE_THROW(u->get(20), Slicer::NoRowsReturned);
+}
+
+BOOST_AUTO_TEST_CASE( find )
+{
+ auto user = u->find("testuser");
+ 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_AUTO_TEST_CASE( findMissing )
+{
+ BOOST_REQUIRE_THROW(u->find("nobody"), Slicer::NoRowsReturned);
+}
+
+BOOST_AUTO_TEST_CASE( deleteCheck )
+{
+ u->get(3);
+ u->remove(3, "wrongpass");
+ u->get(3);
+ u->remove(3, "testpass");
+ BOOST_REQUIRE_THROW(u->get(3), Slicer::NoRowsReturned);
+}
+
+BOOST_AUTO_TEST_CASE( track )
+{
+ u->track(1, 44473);
+}
+
+BOOST_AUTO_TEST_CASE( untrack )
+{
+ u->untrack(1, 44473);
+}
+
BOOST_AUTO_TEST_SUITE_END()