From e2c73d01ca5c55df0fb223ffc42e72c5f2a34097 Mon Sep 17 00:00:00 2001 From: "Sergey (laptop)" Date: Tue, 9 Feb 2021 13:16:55 +0300 Subject: [PATCH] add force_tag_comment_signed --- config/config-sample.ini | 3 +++ extensions/get_tag_comment.php | 8 ++++++++ model/zone.php | 24 +++++++++++++++++++----- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 extensions/get_tag_comment.php diff --git a/config/config-sample.ini b/config/config-sample.ini index ec9b5df..7c5b3bf 100644 --- a/config/config-sample.ini +++ b/config/config-sample.ini @@ -11,6 +11,9 @@ footer = 'Developed by Opera Software.' ;force_change_review = 1 ; Enable this option if you want all users to be forced to enter a comment for every change made. ;force_change_comment = 1 +; Enable this option if you want comment has specific tag in change comment, and resource record comment has the same value. +; You shoud implement function get_tag_comment($login) and place it in ./extensions +;force_tag_comment = 1 [email] enabled = 1 diff --git a/extensions/get_tag_comment.php b/extensions/get_tag_comment.php new file mode 100644 index 0000000..576a8c5 --- /dev/null +++ b/extensions/get_tag_comment.php @@ -0,0 +1,8 @@ +comment)) throw new BadData('A change comment must be provided.'); foreach($update->actions as $action) { try { - $changes[] = $this->process_rrset_action($action, $trash, $revs_missing, $revs_updated); + if(isset($config['web']['force_tag_comment']) && intval($config['web']['force_tag_comment']) == 1) { + $changes[] = $this->process_rrset_action($action, $trash, $revs_missing, $revs_updated, $update->comment); + } else { + $changes[] = $this->process_rrset_action($action, $trash, $revs_missing, $revs_updated); + } } catch(RuntimeException $e) { $errors[] = $e->getMessage(); } @@ -720,7 +724,7 @@ public function process_bulk_json_rrset_update($update, $author = null) { * @param array $revs_missing keep track of reverse zones that are missing * @param array $revs_updated keep track of reverse zones that will be updated */ - private function process_rrset_action($update, &$trash, &$revs_missing, &$revs_updated) { + private function process_rrset_action($update, &$trash, &$revs_missing, &$revs_updated, $change_comment=NULL) { global $active_user, $config, $zone_dir; if(!is_object($update)) throw new BadData('Malformed update.'); if(!(isset($update->name) && isset($update->type))) throw new BadData('Malformed action.'); @@ -766,7 +770,12 @@ private function process_rrset_action($update, &$trash, &$revs_missing, &$revs_u } if(isset($update->comment)) { $comment = new Comment; - $comment->content = $update->comment; + if(isset($change_comment)) { + $tag_comment = get_tag_comment($active_user->uid); + $comment->content = $tag_comment.$change_comment; + } else { + $comment->content = $update->comment; + } $comment->account = $active_user->uid; $rrset->add_comment($comment); } @@ -803,10 +812,15 @@ private function process_rrset_action($update, &$trash, &$revs_missing, &$revs_u } $rrset->add_resource_record($rr); } - if(isset($update->comment) && $update->comment != $rrset->merge_comment_text()) { + if( (isset($update->comment) && $update->comment != $rrset->merge_comment_text()) || isset($change_comment) ) { $rrset->clear_comments(); $comment = new Comment; - $comment->content = $update->comment; + if(isset($change_comment)) { + $tag_comment = get_tag_comment($active_user->uid); + $comment->content = $tag_comment.$change_comment; + } else { + $comment->content = $update->comment; + } $comment->account = $active_user->uid; $rrset->add_comment($comment); }