From 31007554ea15014871eb4d82415c1c6219314c4e Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 28 Mar 2011 13:31:34 -0500 Subject: [PATCH] Added repealing an existing law at Parliament level 5. --- docs/Parliament.pod | 37 +++++++++++++++++++ .../DB/Result/Propositions/RepealLaw.pm | 20 ++++++++++ lib/Lacuna/RPC/Building/Parliament.pm | 35 +++++++++++++++++- t/Parliament.t | 5 ++- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/RepealLaw.pm diff --git a/docs/Parliament.pod b/docs/Parliament.pod index dedc3878..a3d24e52 100644 --- a/docs/Parliament.pod +++ b/docs/Parliament.pod @@ -162,6 +162,43 @@ An explict reason why the BFG should be fired upon the target. Same rules as an +=head2 propose_repeal_law ( session_id, building_id, law_id ) + +Repeal an existing law. + + { + "status" : { ... }, + "proposition" : { + "id" : "id-goes-here", + "name" : "Repeal Writ of Centure", + "description" : "Repeal this law: Jamie Vrbsky is bad at playing Lacuna!", + "votes_needed" : 7, + "votes_yes" : 0, + "votes_no" : 0, + "status" : "Pending", + "date_ends" : "01 31 2010 13:09:05 +0600", + "proposed_by" : { + "id" : "id-goes-here", + "name" : "Klingons", + } + } + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the parliament. + +=head3 law_id + +The id of a law to repeal. + + + + =head2 propose_transfer_station_ownership ( session_id, building_id, to_empire_id ) diff --git a/lib/Lacuna/DB/Result/Propositions/RepealLaw.pm b/lib/Lacuna/DB/Result/Propositions/RepealLaw.pm new file mode 100644 index 00000000..fc69c663 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/RepealLaw.pm @@ -0,0 +1,20 @@ +package Lacuna::DB::Result::Propositions::RepealLaw; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $law = Lacuna->db->resultset('Lacuna::DB::Result::Laws')->find($self->scratch->{law_id}); + if (defined $law) { + $law->delete; + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the law was already repealed, effectively nullifying the vote.'); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index 3235d4ae..a398e560 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -216,8 +216,41 @@ sub propose_seize_star { }; } +sub propose_repeal_law { + my ($self, $session_id, $building_id, $law_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 5) { + confess [1013, 'Parliament must be level 5 to repeal a low.',5]; + } + unless ($law_id) { + confess [1002, 'Must specify a law id to repeal.']; + } + my $law = $self->body->laws->find($law_id); + unless (defined $law) { + confess [1002, 'Could not find the law.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'RepealLaw', + name => 'Repeal '.$law->name, + description => 'Repeal the law described as: '.$law->description, + scratch => { law_id => $law->id }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + -__PACKAGE__->register_rpc_method_names(qw(propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); +__PACKAGE__->register_rpc_method_names(qw(propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/t/Parliament.t b/t/Parliament.t index 43403f36..b6398673 100644 --- a/t/Parliament.t +++ b/t/Parliament.t @@ -56,11 +56,14 @@ $result = $tester->post('parliament', 'cast_vote', [$session_id, $par->id, $resu $result = $tester->post('parliament', 'view_laws', [$session_id, $station->id]); is($result->{result}{laws}[0]{name}, 'Do the big thing.', 'writ enacted'); +$result = $tester->post('parliament', 'propose_repeal', [$session_id, $par->id]); +is($result->{error}{data}, 5, 'repealing law requires level 5 parliament'); + $result = $tester->post('parliament', 'propose_transfer_station_ownership', [$session_id, $par->id]); is($result->{error}{data}, 6, 'transfering ownership of station requires level 6 parliament'); $result = $tester->post('parliament', 'propose_seize_star', [$session_id, $par->id]); -is($result->{error}{data}, 7, 'transfering ownership of station requires level 7 parliament'); +is($result->{error}{data}, 7, 'seizing star requires level 7 parliament'); $result = $tester->post('parliament', 'propose_fire_bfg', [$session_id, $par->id]); is($result->{error}{data}, 30, 'firing bfg requires level 30 parliament'); -- 2.51.2