Skip to content

Commit

Permalink
remove active user
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Nov 29, 2013
1 parent d99a162 commit cdf602d
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 171 deletions.
25 changes: 0 additions & 25 deletions app/assets/javascripts/app/controllers/users/pending.module.coffee

This file was deleted.

8 changes: 0 additions & 8 deletions app/assets/javascripts/app/key_binding.module.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ class KeyBinding

rKey: (e) =>
return if e.metaKey or e.shiftKey
return unless @hasActiveUser()
return unless @getPost()

e.preventDefault()
PostBody.open(@getPost())

uKey: (e) =>
return unless @hasActiveUser()

e.preventDefault()
@getPost()?.vote(@getUser())

Expand All @@ -64,8 +61,6 @@ class KeyBinding
Shortcuts.open()

nKey: (e) =>
return unless @hasActiveUser()

e.preventDefault()
NewPost.open()

Expand All @@ -77,7 +72,4 @@ class KeyBinding
getPost: =>
State.get('post')

hasActiveUser: =>
State.hasActiveUser()

module.exports = KeyBinding
15 changes: 2 additions & 13 deletions app/assets/javascripts/app/state.module.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Model = require('model')
User = -> require('app/models/user')
AuthorizeUser = -> require('app/controllers/users/authorize')
PendingUser = -> require('app/controllers/users/pending')
Manifesto = -> require('app/controllers/users/manifesto')

class State extends Model
Expand All @@ -15,11 +14,8 @@ class State extends Model

withActiveUser: (callback) =>
@withUser (user) =>
if user.get('active')
@withSeenManifesto =>
callback.call(this, user)
else
PendingUser().open()
@withSeenManifesto =>
callback.call(this, user)

withSeenManifesto: (callback) =>
@withUser (user) =>
Expand All @@ -29,9 +25,6 @@ class State extends Model
else
callback.call(this, user)

hasActiveUser: =>
!!@get('user')?.get('active')

hasAdminUser: =>
!!@get('user')?.get('admin')

Expand All @@ -42,10 +35,6 @@ class State extends Model
AuthorizeUser().open()
return false

unless user.get('active')
PendingUser().open()
return false

unless user.get('manifesto')
Manifesto().open()
return false
Expand Down
14 changes: 6 additions & 8 deletions app/assets/javascripts/app/views/sidebar/user_menu.jst.eco
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<li><a data-name="profile">Profile</a></li>

<% if @user.get('active'): %>
<li>
<a data-name="invite">
Invites
(<strong><%= @user.get('invites_count') %></strong>)
</a>
</li>
<% end %>
<li>
<a data-name="invite">
Invites
(<strong><%= @user.get('invites_count') %></strong>)
</a>
</li>

<li><a data-name="feedback">Feedback</a></li>

Expand Down
28 changes: 0 additions & 28 deletions app/assets/javascripts/app/views/users/pending.jst.eco

This file was deleted.

55 changes: 0 additions & 55 deletions app/assets/stylesheets/app/users_pending.css.styl

This file was deleted.

1 change: 0 additions & 1 deletion app/extensions/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def registered(app)
app.set(:auth) do |type|
condition do
error 403 unless current_user?
error 403 if type == :active_user && !current_user.active?
error 403 if type == :admin && !current_user.admin?
end
end
Expand Down
22 changes: 0 additions & 22 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ module Brisk
module Models
class User < Sequel::Model
dataset_module do
def pending
where(active: false)
end

def active
where(active: true)
end

def ordered
order(:created_at.desc)
end
Expand Down Expand Up @@ -83,14 +75,6 @@ def avatar_url
auth_info[:image] || Gravatar.url(email || id)
end

def active?
!!active
end

def pending?
!active
end

def admin?
!!admin
end
Expand All @@ -109,10 +93,6 @@ def decrement_invites!(count = 1)

def activate!(invite = nil)
invite.use!(self) if invite
update_all(
active: true,
activated_at: Time.now
)
end

def notify_activate!
Expand Down Expand Up @@ -191,8 +171,6 @@ def as_safe_json(options = nil)
github: github,
about: about,
karma: karma,
active: active,
activated_at: activated_at,
avatar_url: avatar_url,
created_at: created_at
}
Expand Down
6 changes: 3 additions & 3 deletions app/routes/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class Comments < Base
json comment
end

post '/v1/comments/:id/vote', :auth => :active_user do
post '/v1/comments/:id/vote', :auth => true do
comment = Comment.first!(id: params[:id])
comment.vote!(current_user)
json comment
end

put '/v1/comments/:id', :auth => :active_user do
put '/v1/comments/:id', :auth => true do
if current_user.admin?
comment = Comment.first!(id: params[:id])
else
Expand All @@ -23,7 +23,7 @@ class Comments < Base
json comment
end

post '/v1/comments', :auth => :active_user do
post '/v1/comments', :auth => true do
comment = Comment.new
comment.user = current_user
comment.set_fields(params, [:body, :parent_id, :post_id])
Expand Down
6 changes: 3 additions & 3 deletions app/routes/posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Posts < Base
redirect post.url
end

post '/v1/posts', :auth => :active_user do
post '/v1/posts', :auth => true do
existing = Post.today.url(params[:url]).first

if existing
Expand All @@ -91,7 +91,7 @@ class Posts < Base
json post
end

post '/v1/posts/:id/vote', :auth => :active_user do
post '/v1/posts/:id/vote', :auth => true do
post = Post.first!(id: params[:id])
post.vote!(current_user)

Expand All @@ -115,7 +115,7 @@ class Posts < Base
end
end

post '/v1/posts/:id/comments', :auth => :active_user do
post '/v1/posts/:id/comments', :auth => true do
post = Post.first!(id: params[:id])
comment = Comment.new
comment.post = post
Expand Down
2 changes: 1 addition & 1 deletion app/routes/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Users < Base
json user
end

post '/v1/users/invite', :auth => :active_user do
post '/v1/users/invite', :auth => true do
unless current_user.admin?
unless current_user.invites_count > 0
error 422
Expand Down
8 changes: 8 additions & 0 deletions db/migrations/003_remove_users_active.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Sequel.migration do
change do
alter_table :users do
drop_column :active
drop_column :activated_at
end
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
String :auth
DateTime :created_at
DateTime :updated_at
TrueClass :active, :default=>false
TrueClass :admin, :default=>false
TrueClass :registered
foreign_key :parent_id, :users, :type=>String, :key=>[:id]
Integer :invites_count, :default=>0
String :github, :text=>true
DateTime :activated_at
String :secret, :text=>true
TrueClass :manifesto, :default=>false

Expand Down Expand Up @@ -56,6 +54,7 @@
String :body, :text=>true
String :summary, :text=>true
String :tweet_id, :text=>true
DateTime :scheduled_at
DateTime :published_at
Integer :comment_count, :default=>0, :null=>false
Integer :comments_count, :default=>0, :null=>false
Expand Down
3 changes: 1 addition & 2 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ CREATE TABLE posts (
body text,
summary text,
tweet_id text,
scheduled_at timestamp without time zone,
published_at timestamp without time zone,
comment_count integer DEFAULT 0 NOT NULL,
comments_count integer DEFAULT 0 NOT NULL,
Expand Down Expand Up @@ -373,13 +374,11 @@ CREATE TABLE users (
auth json,
created_at timestamp without time zone,
updated_at timestamp without time zone,
active boolean DEFAULT false,
admin boolean DEFAULT false,
registered boolean,
parent_id uuid,
invites_count integer DEFAULT 0,
github text,
activated_at timestamp without time zone,
secret text,
manifesto boolean DEFAULT false
);
Expand Down

2 comments on commit cdf602d

@raybesiga
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maccman Is this the code that worked for the invites or is it only for removing the active user? Where can i find the original code for working invites? Thanks

@aendra-rininsland
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raybesiga My logic is that this is the last commit app/assets/javascripts/app/views/users/pending.jst.eco is in, which is the pending invite screen shown on monocle.io when users try to post after logging in for the first time. Could very well be that there's more to this commit than simply removing the invite system.

Please sign in to comment.