diff --git a/content/createthread.cpp b/content/createthread.cpp index 3cf7c84..cd3d2d1 100755 --- a/content/createthread.cpp +++ b/content/createthread.cpp @@ -94,6 +94,7 @@ void Content::PostFunCreateThread() return; ReadItem(request.item, Item::dir); + SetUser(request.item); ReadThread(request.thread); request.item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty diff --git a/content/createticket.cpp b/content/createticket.cpp index a8f40a2..131bdd3 100755 --- a/content/createticket.cpp +++ b/content/createticket.cpp @@ -182,6 +182,7 @@ void Content::PostFunCreateTicket() return; ReadItem(request.item, Item::dir); + SetUser(request.item); ReadTicket(request.ticket); request.item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty diff --git a/content/editticket.cpp b/content/editticket.cpp index bc45ca8..22764ac 100755 --- a/content/editticket.cpp +++ b/content/editticket.cpp @@ -138,8 +138,9 @@ void Content::PostFunEditTicket() if( !FunEditTicketCheckAccess() ) return; - ReadItem(request.item, Item::dir); + // co z uzytkownikiem i grupš? chyba nie wczytane? !!! (wczesniej bylo SetUser() w ReadItem() - teraz nie ma) + // dodac informacje o modyfikacji !!! if( !FunCreateTicketCheckAbuse() ) { diff --git a/content/emacs.cpp b/content/emacs.cpp index f38ec08..6e63231 100755 --- a/content/emacs.cpp +++ b/content/emacs.cpp @@ -56,8 +56,14 @@ void Content::PostFunEmacsAdd(Item & item) void Content::PostFunEmacsEdit(bool with_url) { + if( request.session->puser ) + request.item.modification_user_id = request.session->puser->id; + else + request.item.modification_user_id = -1; + request.item.SetDateModifyToNow(); request.status = db.EditItemById(request.item, with_url); + if( request.status == WINIX_ERR_OK ) { @@ -131,6 +137,7 @@ void Content::PostFunEmacs() { request.is_item = true; request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask + SetUser(request.item); PostFunEmacsAdd(request.item); } else diff --git a/content/misc_item.cpp b/content/misc_item.cpp index 12bb5b7..5f99bde 100755 --- a/content/misc_item.cpp +++ b/content/misc_item.cpp @@ -114,8 +114,6 @@ bool Content::ReadItem(Item & item, Item::Type item_type) bool edit_with_url = ReadItemUrlSubject(item, item_type); - SetUser(item); - if( item_type == Item::file ) ReadItemContentWithType(item); diff --git a/content/mkdir.cpp b/content/mkdir.cpp index 61e95e6..a03cf46 100755 --- a/content/mkdir.cpp +++ b/content/mkdir.cpp @@ -51,6 +51,7 @@ void Content::PostFunMkdir(bool add_to_dir_table, int privileges) return; ReadItem(request.item, Item::dir); + SetUser(request.item); request.item.privileges = privileges; Mkdir(request.item, add_to_dir_table); diff --git a/content/upload.cpp b/content/upload.cpp index d69afa1..970b4be 100755 --- a/content/upload.cpp +++ b/content/upload.cpp @@ -136,6 +136,7 @@ void Content::UploadSingle() bool has_url = (new_url && (*new_url)[0] != 0 ); ReadItem(request.item, Item::file); // ReadItem() changes the url if it is empty + SetUser(request.item); request.item.privileges = 0644; // !! tymczasowo const char * file_name = request.post_file_table.begin()->second.filename.c_str(); diff --git a/core/db.cpp b/core/db.cpp index b6489a8..fdf52e6 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -455,9 +455,10 @@ Error Db::AddItemIntoItem(Item & item) { AssertConnection(); std::ostringstream query; - query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, " + query << "insert into core.item (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, " "parent_id, content_id, auth, auth_path, default_item, subject, guest_name, url) values ("; query << '\'' << item.user_id << "', "; + query << '\'' << item.modification_user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; query << '\'' << ConvertTime(item.date_creation) << "', "; @@ -562,7 +563,7 @@ Error Db::EditItemInItem(Item & item, bool with_url) { AssertConnection(); std::ostringstream query; - query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, " + query << "update core.item set (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, " "default_item, parent_id, subject, guest_name, auth, auth_path"; if( with_url ) @@ -570,6 +571,7 @@ Error Db::EditItemInItem(Item & item, bool with_url) query << ") = ("; query << '\'' << item.user_id << "', "; + query << '\'' << item.modification_user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; query << '\'' << ConvertTime(item.date_creation) << "', "; @@ -795,7 +797,7 @@ PGresult * Db::GetItemsQuery(const ItemQuery & iq) query << "select item.id"; if( iq.sel_parent_id ) query << " ,parent_id"; - if( iq.sel_user_id ) query << " ,user_id"; + if( iq.sel_user_id ) query << " ,user_id, modification_user_id"; if( iq.sel_group_id ) query << " ,group_id"; if( iq.sel_guest_name) query << " ,guest_name"; if( iq.sel_privileges ) query << " ,privileges"; @@ -1092,7 +1094,7 @@ bool result = false; AssertConnection(); std::ostringstream query; - query << "select user_id, group_id, privileges, guest_name from core.item" + query << "select user_id, modification_user_id, group_id, privileges, guest_name from core.item" << " where item.id='" << id << "';"; r = AssertQuery( query.str() ); @@ -1129,8 +1131,9 @@ Error Db::EditPrivById(Item & item, long id) { AssertConnection(); std::ostringstream query; - query << "update core.item set (user_id, group_id, privileges, guest_name) = ("; + query << "update core.item set (user_id, modification_user_id, group_id, privileges, guest_name) = ("; query << '\'' << item.user_id << "', "; + query << '\'' << item.modification_user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; query << '\'' << Escape(item.guest_name) << "' "; diff --git a/core/db.h b/core/db.h index e0615ab..563d7b9 100755 --- a/core/db.h +++ b/core/db.h @@ -56,7 +56,7 @@ public: { // id is selected always bool sel_parent_id; // parent_id - bool sel_user_id; // user_id + bool sel_user_id; // user_id, modification_user_id bool sel_group_id; // group_id bool sel_guest_name; // guest_name bool sel_privileges; // privileges @@ -223,7 +223,7 @@ protected: struct ItemColumns { int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, - content_id, default_item, subject, content, content_type, guest_name, auth, auth_path; + content_id, default_item, subject, content, content_type, guest_name, auth, auth_path, modification_user_id; void SetColumns(PGresult * r); void SetItem(PGresult * r, long row, Item & item); diff --git a/core/db_itemcolumns.cpp b/core/db_itemcolumns.cpp index 31f45ef..22ad2e7 100755 --- a/core/db_itemcolumns.cpp +++ b/core/db_itemcolumns.cpp @@ -31,6 +31,7 @@ void Db::ItemColumns::SetColumns(PGresult * r) guest_name = PQfnumber(r, "guest_name"); auth = PQfnumber(r, "auth"); auth_path = PQfnumber(r, "auth_path"); + modification_user_id = PQfnumber(r, "modification_user_id"); } @@ -54,6 +55,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item) if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name); if( auth != -1 ) item.auth = static_cast( atoi(Db::AssertValue(r, row, auth)) ); if( auth_path != -1 ) item.auth_path = Db::AssertValue(r, row, auth_path); + if( modification_user_id != -1 ) item.modification_user_id = atol( Db::AssertValue(r, row, modification_user_id) ); } diff --git a/core/item.h b/core/item.h index 212f6de..7941b8b 100755 --- a/core/item.h +++ b/core/item.h @@ -25,6 +25,8 @@ long user_id; long group_id; std::string guest_name; // used as a user name when user_id is equal -1 +long modification_user_id; // who has modified the item last (not taken into account when checking permissions) + int privileges; tm date_creation; @@ -109,7 +111,8 @@ void Clear() user_id = -1; group_id = -1; privileges = 0; - + modification_user_id = -1; + guest_name.clear(); subject.clear(); diff --git a/html/item_info.html b/html/item_info.html index 7d7d4a2..2758bd9 100755 --- a/html/item_info.html +++ b/html/item_info.html @@ -1 +1 @@ -

{added_by}: [item_user], [item_date_creation_nice][if-no item_dates_equal], {last_modified}: [item_date_modification_nice][end]

+

{added_by}: [item_user], [item_date_creation_nice][if-no item_dates_equal], {last_modified}[if-one item_users_different] {by}: [item_modification_user], [else]: [end][item_date_modification_nice][end]

diff --git a/html/item_tab_info.html b/html/item_tab_info.html index 71a5856..f5f49a4 100755 --- a/html/item_tab_info.html +++ b/html/item_tab_info.html @@ -1 +1 @@ -

{added_by}: [item_tab_user], [item_tab_date_creation_nice][if-no item_tab_dates_equal], {last_modified}: [item_tab_date_modification_nice][end]

+

{added_by}: [item_tab_user], [item_tab_date_creation_nice][if-no item_tab_dates_equal], {last_modified}[if-one item_tab_users_different] {by}: [item_tab_modification_user], [else]: [end][item_tab_date_modification_nice][end]

diff --git a/locale/en b/locale/en index 254c84a..1950284 100755 --- a/locale/en +++ b/locale/en @@ -20,6 +20,7 @@ req_per_sec = Requests per second added_by = Added by last_modified = Last modified +by = by error_404 = Error 404 error_404_msg = We are sory but there is no such a page in our service. diff --git a/locale/pl b/locale/pl index bfc66a4..97de25f 100755 --- a/locale/pl +++ b/locale/pl @@ -20,6 +20,7 @@ req_per_sec = wywo added_by = Dodane przez last_modified = ostatnio modyfikowany +by = przez error_404 = Błąd 404 error_404_msg = Przykro nam ale podanej strony nie ma w naszym serwisie. diff --git a/templates/item.cpp b/templates/item.cpp index 0d64517..4d8d256 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -21,6 +21,22 @@ namespace TemplatesFunctions +void print_user_name(Info & i, const User * puser, const std::string & guest_name) +{ + if( puser ) + { + HtmlEscape(i.out, puser->name); + } + else + { + i.out << "~"; + + if( !guest_name.empty() ) + HtmlEscape(i.out, guest_name); + else + i.out << "guest"; // !! dodac do konfiga + } +} @@ -208,18 +224,21 @@ void item_info(Info & i) void item_user(Info & i) { User * puser = data.users.GetUser(request.item.user_id); - - if( puser ) - HtmlEscape(i.out, puser->name); - else - { - i.out << "~"; - - if( !request.item.guest_name.empty() ) - HtmlEscape(i.out, request.item.guest_name); - else - i.out << "guest"; // !! dodac do konfiga - } + print_user_name(i, puser, request.item.guest_name); +} + + + +void item_modification_user(Info & i) +{ + User * puser = data.users.GetUser(request.item.modification_user_id); + print_user_name(i, puser, request.item.guest_name); +} + + +void item_users_different(Info & i) +{ + i.res = (request.item.user_id != request.item.modification_user_id); } @@ -434,22 +453,33 @@ void item_tab_user(Info & i) if( item_index < request.item_table.size() ) { User * puser = data.users.GetUser(request.item_table[item_index].user_id); - - if( puser ) - HtmlEscape(i.out, puser->name); - else - { - i.out << "~"; - - if( !request.item_table[item_index].guest_name.empty() ) - HtmlEscape(i.out, request.item_table[item_index].guest_name); - else - i.out << "guest"; // !! dodac do konfiga - } + print_user_name(i, puser, request.item_table[item_index].guest_name); } } + +void item_tab_modification_user(Info & i) +{ + if( item_index < request.item_table.size() ) + { + User * puser = data.users.GetUser(request.item_table[item_index].modification_user_id); + print_user_name(i, puser, request.item_table[item_index].guest_name); + } +} + + + +void item_tab_users_different(Info & i) +{ + if( item_index < request.item_table.size() ) + { + i.res = (request.item_table[item_index].user_id != request.item_table[item_index].modification_user_id); + } +} + + + void item_tab_group(Info & i) { if( item_index < request.item_table.size() ) @@ -492,17 +522,22 @@ void item_tab_date_creation_nice(Info & i) if( item_index < request.item_table.size() ) { tm * ptm = &request.item_table[item_index].date_creation; - TemplatesMisc::print_date_nice(i, ptm); + TemplatesMisc::print_date_nice(i, ptm); + + i.out << ""; } } + void item_tab_date_modification_nice(Info & i) { if( item_index < request.item_table.size() ) { tm * ptm = &request.item_table[item_index].date_modification; - TemplatesMisc::print_date_nice(i, ptm); + TemplatesMisc::print_date_nice(i, ptm); + + i.out << ""; } } @@ -520,15 +555,6 @@ void item_tab_dates_equal(Info & i) ptm1->tm_hour == ptm2->tm_hour && ptm1->tm_min == ptm2->tm_min && ptm1->tm_sec == ptm2->tm_sec; - - i.out << ""; } } diff --git a/templates/misc.cpp b/templates/misc.cpp index 583f260..0ccb430 100755 --- a/templates/misc.cpp +++ b/templates/misc.cpp @@ -17,11 +17,14 @@ namespace TemplatesMisc { -void print_date_nice(Ezc::Info & i, tm * ptm) +void print_date_nice(Ezc::Info & i, const tm * ptm) { - time_t t = mktime(ptm); + tm tm_temp(*ptm); + + time_t t = mktime(&tm_temp); // mktime do something in tm_temp time_t now = time(0); time_t one_day = 60 * 60 * 24; + if( t + one_day > now ) i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); diff --git a/templates/misc.h b/templates/misc.h index 997539a..64332a6 100755 --- a/templates/misc.h +++ b/templates/misc.h @@ -25,7 +25,7 @@ namespace TemplatesMisc typedef std::vector > Patterns; -void print_date_nice(Ezc::Info & i, tm * ptm); +void print_date_nice(Ezc::Info & i, const tm * ptm); diff --git a/templates/templates.cpp b/templates/templates.cpp index 0d91b0c..04fc774 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -216,6 +216,8 @@ void Templates::CreateFunctions() functions.Insert("item_can_remove", item_can_remove); functions.Insert("item_info", item_info); functions.Insert("item_user", item_user); + functions.Insert("item_modification_user", item_modification_user); + functions.Insert("item_users_different", item_users_different); functions.Insert("item_date_creation", item_date_creation); functions.Insert("item_date_modification", item_date_modification); functions.Insert("item_date_creation_nice", item_date_creation_nice); @@ -239,9 +241,11 @@ void Templates::CreateFunctions() functions.Insert("item_tab_can_read", item_tab_can_read); functions.Insert("item_tab_info", item_tab_info); functions.Insert("item_tab_user", item_tab_user); + functions.Insert("item_tab_modification_user", item_tab_modification_user); + functions.Insert("item_tab_users_different", item_tab_users_different); functions.Insert("item_tab_group", item_tab_group); - functions.Insert("item_tab_date_creation", item_tab_date_creation); - functions.Insert("item_tab_date_modification", item_tab_date_modification); + functions.Insert("item_tab_date_creation", item_tab_date_creation); + functions.Insert("item_tab_date_modification", item_tab_date_modification); functions.Insert("item_tab_date_creation_nice", item_tab_date_creation_nice); functions.Insert("item_tab_date_modification_nice", item_tab_date_modification_nice); functions.Insert("item_tab_dates_equal", item_tab_dates_equal); diff --git a/templates/templates.h b/templates/templates.h index 4dac678..a3bb336 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -127,6 +127,8 @@ namespace TemplatesFunctions void item_can_remove(Info & i); void item_info(Info & i); void item_user(Info & i); + void item_modification_user(Info & i); + void item_users_different(Info & i); void item_date_creation(Info & i); void item_date_modification(Info & i); void item_date_creation_nice(Info & i); @@ -150,6 +152,8 @@ namespace TemplatesFunctions void item_tab_can_read(Info & i); void item_tab_info(Info & i); void item_tab_user(Info & i); + void item_tab_modification_user(Info & i); + void item_tab_users_different(Info & i); void item_tab_group(Info & i); void item_tab_date_creation(Info & i); void item_tab_date_modification(Info & i);