mirror of https://github.com/Icinga/icinga2.git
/v1/actions/remove-comment: let users specify themselves
This commit is contained in:
parent
7849da0b78
commit
d84efecb62
|
@ -280,12 +280,18 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
|
|||
Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
|
||||
const Dictionary::Ptr& params)
|
||||
{
|
||||
auto author (HttpUtility::GetLastParameter(params, "author"));
|
||||
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
||||
|
||||
if (checkable) {
|
||||
std::set<Comment::Ptr> comments = checkable->GetComments();
|
||||
|
||||
for (const Comment::Ptr& comment : comments) {
|
||||
{
|
||||
ObjectLock oLock (comment);
|
||||
comment->SetRemovedBy(author);
|
||||
}
|
||||
|
||||
Comment::RemoveComment(comment->GetName());
|
||||
}
|
||||
|
||||
|
@ -297,6 +303,11 @@ Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
|
|||
if (!comment)
|
||||
return ApiActions::CreateResult(404, "Cannot remove non-existent comment object.");
|
||||
|
||||
{
|
||||
ObjectLock oLock (comment);
|
||||
comment->SetRemovedBy(author);
|
||||
}
|
||||
|
||||
String commentName = comment->GetName();
|
||||
|
||||
Comment::RemoveComment(commentName);
|
||||
|
|
|
@ -73,6 +73,8 @@ class Comment : ConfigObject < CommentNameComposer
|
|||
[config] bool persistent;
|
||||
[config] Timestamp expire_time;
|
||||
[state] int legacy_id;
|
||||
|
||||
[no_user_view, no_user_modify] String removed_by;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1485,7 +1485,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
|
|||
"comment_id", GetObjectIdentifier(comment),
|
||||
"environment_id", SHA1(GetEnvironment()),
|
||||
"entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
|
||||
"author", Utility::ValidateUTF8(comment->GetAuthor()),
|
||||
"author", Utility::ValidateUTF8(comment->GetRemovedBy()),
|
||||
"comment", Utility::ValidateUTF8(comment->GetText()),
|
||||
"entry_type", Convert::ToString(comment->GetEntryType()),
|
||||
"is_persistent", Convert::ToString((unsigned short)comment->GetPersistent()),
|
||||
|
|
Loading…
Reference in New Issue