Skip to content

Commit

Permalink
Disable hovercards for logged out users and prevent redirect to sign …
Browse files Browse the repository at this point in the history
…in page

closes diaspora#6587
  • Loading branch information
Steffen van Bergerem authored and jhass committed Dec 17, 2015
1 parent f0fc62e commit 2025fae
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
## Bug fixes
* Fix mention autocomplete when pasting the username [#6510](https://github.com/diaspora/diaspora/pull/6510)
* Use and update updated\_at for notifications [#6573](https://github.com/diaspora/diaspora/pull/6573)
* Ensure the author signature is checked when receiving a relayable [#6539](https://github.com/diaspora/diaspora/pull/6539)
* Ensure the author signature is checked when receiving a relayable [#6539](https://github.com/diaspora/diaspora/pull/6539)
* Do not try to display hovercards when logged out [#6587](https://github.com/diaspora/diaspora/pull/6587)

## Features

Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/app/views/hovercard_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ app.views.Hovercard = app.views.Base.extend({
this.hashtags = this.$('.hashtags');
this.person_link = this.$('a.person');
this.person_handle = this.$('div.handle');
this.active = true;
this.active = app.currentUser.authenticated();
},

postRenderTemplate: function() {
Expand Down Expand Up @@ -97,7 +97,7 @@ app.views.Hovercard = app.views.Base.extend({
href += "/hovercard.json";

var self = this;
$.get(href, function(person){
$.ajax(href, {preventGlobalErrorHandling: true}).done(function(person){
if( !person || person.length === 0 ) {
throw new Error("received data is not a person object");
}
Expand Down Expand Up @@ -130,7 +130,7 @@ app.views.Hovercard = app.views.Base.extend({
// TODO render me client side!!!
var href = this.href();
href += "/aspect_membership_button";
$.get(href, function(response) {
$.ajax(href, {preventGlobalErrorHandling: true}).done(function(response){
self.dropdown_container.html(response);
});
new app.views.AspectMembership({el: self.dropdown_container});
Expand Down
53 changes: 48 additions & 5 deletions spec/javascripts/app/views/hovercard_view_spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
describe("app.views.Hovercard", function() {
beforeEach(function() {
this.view = new app.views.Hovercard();
context("user not signed in", function() {
beforeEach(function() {
logout();
this.view = new app.views.Hovercard();
});

describe("initialize", function() {
it("deactivates hovercards", function() {
expect(this.view.active).toBeFalsy();
});
});
});

describe("mouseIsOverElement", function() {
it("returns false if the element is undefined", function() {
expect(this.view.mouseIsOverElement(undefined, $.Event())).toBeFalsy();
context("user signed in", function() {
beforeEach(function() {
loginAs(factory.userAttrs());
this.view = new app.views.Hovercard();
});

describe("initialize", function() {
it("activates hovercards", function() {
expect(this.view.active).toBeTruthy();
});
});

describe("mouseIsOverElement", function() {
it("returns false if the element is undefined", function() {
expect(this.view.mouseIsOverElement(undefined, $.Event())).toBeFalsy();
});
});

describe("_populateHovercard", function() {
it("prevents global error handling for the ajax call", function() {
spyOn(jQuery, "ajax").and.callThrough();
this.view.parent = spec.content();
this.view._populateHovercard();
expect(jQuery.ajax).toHaveBeenCalledWith("undefined/hovercard.json", {preventGlobalErrorHandling: true});
});
});

describe("_populateHovercardWith", function() {
it("prevents global error handling for the ajax call", function() {
spyOn(jQuery, "ajax").and.callThrough();
this.view.parent = spec.content();
this.view._populateHovercardWith({});
expect(jQuery.ajax).toHaveBeenCalledWith(
"undefined/aspect_membership_button",
{preventGlobalErrorHandling: true}
);
});
});
});
});

0 comments on commit 2025fae

Please sign in to comment.