Added ability to store creator, updater, date of create and date of edit on entities- columns for this added to Voucher and CampData.

Removed permission check from Service::loadById- caused access violation when user had not have read permission.
This commit is contained in:
2017-08-21 14:16:43 +02:00
parent eff4190c99
commit 836521e533
11 changed files with 176 additions and 4 deletions
+5
View File
@@ -5,6 +5,11 @@ System::System()
}
System::~System()
{
}
int System::id() const
{
return m_id;
+1
View File
@@ -11,6 +11,7 @@ class CORESHARED_EXPORT System
{
public:
System();
virtual ~System();
int id() const;
void setId(int id);
+28 -2
View File
@@ -82,6 +82,8 @@ public:
Transaction tx;
addDateAndUser(entity, true);
try
{
db->persist(entity);
@@ -108,6 +110,8 @@ public:
Transaction tx;
addDateAndUser(entity, false);
try
{
db->update(entity);
@@ -126,9 +130,9 @@ public:
QSharedPointer<T> loadById(int id) {
QSharedPointer<T> entity;
if (!checkPermission(PERM_READ)) {
/*if (!checkPermission(PERM_READ)) {
return entity;
}
}*/
odb::database *db = Context::instance().db();
@@ -233,6 +237,28 @@ protected:
return true;
}
void addDateAndUser(QSharedPointer<T> entity, bool creating) {
T *inner = entity.data();
QObject *obj = dynamic_cast<QObject*>(inner);
if (obj == NULL)
{
return;
}
if (creating)
{
obj->setProperty("createdBy", Context::instance().currentUser()->login());
obj->setProperty("created", QDateTime::currentDateTime());
}
else
{
obj->setProperty("updatedBy", Context::instance().currentUser()->login());
obj->setProperty("updated", QDateTime::currentDateTime());
}
}
};
#endif // SERVICE_H