Permalink
Browse files

Merge branch 'master' into bootstrap3

  • Loading branch information...
2 parents 459bbcf + affb649 commit ccdc76ad2ddb0cc69ff6fd0318c4c3cdaacf2c4a @rizen rizen committed Oct 31, 2013
Showing with 111 additions and 7 deletions.
  1. +3 −0 CHANGES.txt
  2. +28 −0 lib/Wing/Rest/Wingman.pm
  3. +12 −0 lib/Wing/Session.pm
  4. +2 −1 lib/Wing/Web/Account.pm
  5. +51 −6 lib/Wingman.pm
  6. +6 −0 public/wing.js
  7. +9 −0 var/init/views/admin/wingman_tube.tt
View
@@ -4,6 +4,9 @@ This file tracks the changes to Wing over time. Especially
with respect to new features and compatibility changes.
==========================================================
+2013-10-30
+ * Changed session to compare the password hash stored in the session with the one stored in the database. This way all existing sessions will get logged out if the user changes their password.
+
2013-09-25
* Daemonized wingman.pl. You now need the Daemon::Control perl module. You can also add a "wingman/pid_file_path" directive to your config file if you want to control where the pid is stored.
* Added --watch-only as a command line flag to wingman.pl so that you can specify a tube to watch other than the default tube. This is useful when you have different servers that you wish to handle different tubes.
@@ -77,6 +77,34 @@ post '/api/wingman/tubes/:tube/pause' => sub {
}
};
+get '/api/wingman/tubes/:tube/jobs/buried' => sub {
+ my $user = get_user_by_session_id()->verify_is_admin();
+ my $job = Wingman->new->peek_buried(params->{tube});
+ if (defined $job) {
+ return $job->describe;
+ }
+ ouch 404, 'No buried jobs.';
+};
+
+get '/api/wingman/tubes/:tube/jobs/ready' => sub {
+ my $user = get_user_by_session_id()->verify_is_admin();
+ my $job = Wingman->new->peek_ready(params->{tube});
+ if (defined $job) {
+ return $job->describe;
+ }
+ ouch 404, 'No ready jobs.';
+};
+
+get '/api/wingman/tubes/:tube/jobs/delayed' => sub {
+ my $user = get_user_by_session_id()->verify_is_admin();
+ my $job = Wingman->new->peek_delayed(params->{tube});
+ if (defined $job) {
+ return $job->describe;
+ }
+ ouch 404, 'No delayed jobs.';
+};
+
+
### JOBS
get '/api/wingman/jobs' => sub {
View
@@ -23,6 +23,7 @@ sub BUILD {
my $self = shift;
my $session_data = Wing->cache->get('session'.$self->id);
if (defined $session_data && ref $session_data eq 'HASH') {
+ $self->password_hash($session_data->{password_hash});
$self->user_id($session_data->{user_id});
$self->extended($session_data->{extended});
$self->ip_address($session_data->{ip_address});
@@ -59,6 +60,11 @@ has user_id => (
},
);
+has password_hash => (
+ is => 'rw',
+ predicate => 'has_password_hash',
+);
+
has user => (
is => 'rw',
predicate => 'has_user',
@@ -104,10 +110,15 @@ sub check_permissions {
sub extend {
my $self = shift;
+ if ($self->password_hash ne $self->user->password) {
+ $self->end;
+ return;
+ }
$self->extended( $self->extended + 1 );
Wing->cache->set(
'session'.$self->id,
{
+ password_hash => $self->password_hash, # this hash is stored here so that if the user changes their password we can log out all existing sessions
user_id => $self->user_id,
extended => $self->extended,
sso => $self->sso,
@@ -136,6 +147,7 @@ sub end {
sub start {
my ($self, $user, $options) = @_;
$self->user_id($user->id);
+ $self->password_hash($user->password);
$user->current_session($self);
$self->user($user);
$self->sso($options->{sso});
@@ -147,7 +147,7 @@ post '/account/apikey/:id' => sub {
get '/account' => sub {
my $user = get_user_by_session_id();
- template 'account/index', { current_user => describe($user, current_user => $user) };
+ template 'account/index', { current_user => describe($user, current_user => $user, include_options => 1, include_relationships => 1) };
};
post '/account' => sub {
@@ -169,6 +169,7 @@ post '/account' => sub {
}
else {
$user->update;
+ login($user); # in case they changed their password
redirect '/account?success_message=Updated successfully.';
}
};
View
@@ -312,45 +312,90 @@ sub peek {
return undef;
}
-=head2 peek_ready ( )
+=head2 peek_ready ( [ tube ] )
Fetch the next ready job without reserving it.
+=over
+
+=item tube
+
+What tube to peek into. Defaults to default tube.
+
+=back
+
=cut
sub peek_ready {
- my ($self) = @_;
+ my ($self, $tube) = @_;
+ my $default_tube = Wing->config->get('wingman/beanstalkd/default_tube');
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($tube);
+ }
my $beanstalk_job = $self->beanstalk->peek_ready;
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($default_tube);
+ }
if (defined $beanstalk_job) {
return $self->_instantiate_job($beanstalk_job);
}
return undef;
}
-=head2 peek_delayed ( )
+=head2 peek_delayed ( [ tube ] )
Fetch the next delayed job without reserving it.
+=over
+
+=item tube
+
+What tube to peek into. Defaults to default tube.
+
+=back
+
=cut
sub peek_delayed {
- my ($self) = @_;
+ my ($self, $tube) = @_;
+ my $default_tube = Wing->config->get('wingman/beanstalkd/default_tube');
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($tube);
+ }
my $beanstalk_job = $self->beanstalk->peek_delayed;
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($default_tube);
+ }
if (defined $beanstalk_job) {
return $self->_instantiate_job($beanstalk_job);
}
return undef;
}
-=head2 peek_buried ( )
+=head2 peek_buried ( [ tube ] )
Fetch the next buried job without reserving it.
+=over
+
+=item tube
+
+What tube to peek into. Defaults to default tube.
+
+=back
+
=cut
sub peek_buried {
- my ($self) = @_;
+ my ($self, $tube) = @_;
+ my $default_tube = Wing->config->get('wingman/beanstalkd/default_tube');
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($tube);
+ }
my $beanstalk_job = $self->beanstalk->peek_buried;
+ if (defined $tube && $tube ne $default_tube) {
+ $self->use($default_tube);
+ }
if (defined $beanstalk_job) {
return $self->_instantiate_job($beanstalk_job);
}
View
@@ -16,6 +16,12 @@ wing.info = function(message) {
});
};
+wing.dump_keys = function(object) {
+ var keys = [];
+ for(var k in object) keys.push(k);
+ wing.info(keys.join(' '));
+};
+
wing.warn = function(message) {
$.pnotify({
addclass: 'alert-warning',
@@ -15,6 +15,9 @@
<th># Kicks</th>
</tr>
</table>
+<button class="btn btn-primary" onclick="return peek('ready');">Peek Ready</button>
+<button class="btn btn-primary" onclick="return peek('delayed');">Peek Delayed</button>
+<button class="btn btn-primary" onclick="return peek('buried');">Peek Buried</button>
<h3>Actions</h3>
<div class="row">
@@ -141,6 +144,12 @@ function add_job() {
});
return false;
}
+
+function peek(type) {
+ wing.ajax('GET', 'wingman/tubes/[% tube_name %]/jobs/' + type, {}, function(data) {
+ window.location = '/admin/wingman/jobs/' + data.result.id;
+ });
+}
</script>
[% END %]
[% INCLUDE admin/footer_include.tt %]

0 comments on commit ccdc76a

Please sign in to comment.