Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add force_tag_comment_signed #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ footer = 'Developed by <a href="https://www.opera.com/">Opera Software</a>.'
;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
Expand Down
8 changes: 8 additions & 0 deletions extensions/get_tag_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

function get_tag_comment($login)
{
$shortname = explode('.', gethostname());
$tag = date("d.m.Y H:i:s")." ".$shortname[0]." \"WEB\" ".$login.": ";
return $tag;
}
24 changes: 19 additions & 5 deletions model/zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,11 @@ public function process_bulk_json_rrset_update($update, $author = null) {
if(isset($config['web']['force_change_comment']) && intval($config['web']['force_change_comment']) == 1 && empty($update->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();
}
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down