-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralise update creation to include fields.
Given the user, we can infer the name if not provided, and the extra data if a staff user. We can also provide defaults for various other fields. Always have superuser take precedence over from_body.
- Loading branch information
Showing
17 changed files
with
107 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
BEGIN { | ||
use File::Basename qw(dirname); | ||
use File::Spec; | ||
my $d = dirname(File::Spec->rel2abs($0)); | ||
require "$d/../setenv.pl"; | ||
} | ||
|
||
use FixMyStreet::DB; | ||
|
||
my $rs = FixMyStreet::DB->resultset("Comment")->search({ | ||
'user.from_body' => { '!=', undef }, | ||
'user.is_superuser' => 0, | ||
'me.extra' => [ undef, { -not_like => '%is_body_user%' } ], | ||
}, { | ||
"+columns" => ["user.from_body"], | ||
join => 'user', | ||
}); | ||
while (my $row = $rs->next) { | ||
my $id = $row->user->{_column_data}->{from_body}; # Avoid DB lookups | ||
$row->set_extra_metadata( is_body_user => $id ); | ||
$row->update; | ||
} | ||
|
||
$rs = FixMyStreet::DB->resultset("Comment")->search({ | ||
'user.is_superuser' => 1, | ||
'me.extra' => [ undef, { -not_like => '%is_superuser%' } ], | ||
}, { | ||
join => 'user', | ||
}); | ||
while (my $row = $rs->next) { | ||
$row->set_extra_metadata( is_superuser => 1 ); | ||
$row->update; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
use FixMyStreet::Test; | ||
|
||
my $comment_rs = FixMyStreet::DB->resultset('Comment'); | ||
my $user = FixMyStreet::DB->resultset('User')->new({ name => 'Test User', is_superuser => 1 }); | ||
|
||
my $comment_rs = FixMyStreet::DB->resultset('Comment'); | ||
my $comment = $comment_rs->new( | ||
{ | ||
user_id => 1, | ||
user => $user, | ||
problem_id => 1, | ||
text => '', | ||
state => 'confirmed', | ||
anonymous => 0, | ||
mark_fixed => 0, | ||
cobrand => 'default', | ||
cobrand_data => '', | ||
} | ||
); | ||
|
||
is $comment->confirmed, undef, 'inflating null confirmed ok'; | ||
is $comment->created, undef, 'inflating null confirmed ok'; | ||
is $comment->created, undef, 'inflating null created ok'; | ||
is $comment->mark_fixed, 0, 'mark fixed default set'; | ||
is $comment->state, 'confirmed', 'state default is confirmed'; | ||
is $comment->name, 'an administrator'; | ||
|
||
$user->is_superuser(0); | ||
$comment = $comment_rs->new({ | ||
user => $user, | ||
problem_id => 1, | ||
text => '', | ||
}); | ||
is $comment->name, 'Test User'; | ||
|
||
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters