Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new subcards api and list/listed_by relations #513

Merged
merged 61 commits into from Oct 9, 2015
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a0386f0
list and listed_by cardtypes
xithan Jul 15, 2015
4de490a
Merge remote-tracking branch 'upstream/master' into listedby
xithan Sep 16, 2015
024a3d5
refactoring subcards
xithan Sep 21, 2015
fb0d1c5
.codeclimate.yml: ingnore assets
xithan Sep 22, 2015
1aa90c8
subcards overhaul
xithan Sep 23, 2015
b0aacba
getting closer to get subcards working
xithan Sep 26, 2015
a043770
correct type count test
xithan Sep 28, 2015
9680251
fetch.rb: refactor #fetch_from_cache_or_db
xithan Sep 28, 2015
ed661f1
let subcards survive #expire
xithan Sep 28, 2015
14c54c5
Merge remote-tracking branch 'wagn/master' into listedby
xithan Sep 29, 2015
34b48eb
.ruby-style.yml: require no parens for method definitions
xithan Sep 29, 2015
9f64fc3
can almost see the green light
xithan Sep 29, 2015
07b2d51
seed tick
xithan Sep 29, 2015
6d3957c
:checkered_flag:
xithan Sep 29, 2015
aac4d61
remove unused #given_name
xithan Sep 29, 2015
66f7bd1
restore wagn logo
xithan Sep 29, 2015
f6ecbe0
houndiness
xithan Sep 29, 2015
54b4c24
check if the listed_by relation makes it to the reference table
xithan Sep 30, 2015
7c5db75
add rubocop config file
xithan Sep 30, 2015
495f156
.ruby-style.yml: leading dot position for multi-line method calls
xithan Sep 30, 2015
d38553d
:dog2:
xithan Sep 30, 2015
08f2c27
:dog2::dog2:
xithan Sep 30, 2015
35dcc67
get features passing
xithan Oct 1, 2015
153c8bd
Merge remote-tracking branch 'wagn/master' into listedby
xithan Oct 1, 2015
aa5df6a
refactor card initialization
xithan Oct 5, 2015
ce2be16
refactor #fetch
xithan Oct 5, 2015
65a274b
machine.rb: update after :expire_related instead of after :store_subc…
xithan Oct 5, 2015
25cc8c1
phase.rb: preparations for phase methods
xithan Oct 5, 2015
3d68e08
move specs from type_spec to initialize_spec
xithan Oct 5, 2015
b83120e
specs clean up
xithan Oct 5, 2015
cf1d443
wagn.rake: update deprecated constant
xithan Oct 5, 2015
8982834
search_type.rb bug: invalid default type if WQL doesn't search for a …
xithan Oct 5, 2015
8e877a5
set.rb: more phase methods
xithan Oct 5, 2015
923f6e3
name.rb: #to_sym for name objects
xithan Oct 5, 2015
d6bc67c
houndiness
xithan Oct 5, 2015
7ad511c
all/subcards.rb: move subcard methods from phases.rb here
xithan Oct 5, 2015
15ccd61
subcards.rb: use local cache only
xithan Oct 5, 2015
b48d200
more houndiness
xithan Oct 5, 2015
2c5d5dd
fetch.rb#fetch_id: treat only symbols as codenames
xithan Oct 6, 2015
12a5142
auth.rb: refactor #needs_setup?
xithan Oct 6, 2015
61900fd
subcards.rb: rename :filter_empty_subcards to :reject_empty_subcards
xithan Oct 6, 2015
847ca40
subcards.rb: renamed #empty? to #unfilled?
xithan Oct 6, 2015
0638ed6
add method for creating active accounts
xithan Oct 6, 2015
06eaf92
subcards.rb: fix for subsubcards
xithan Oct 6, 2015
671ce92
renamed list.rb
xithan Oct 6, 2015
e11bd4c
form.rb: introduce form_root
xithan Oct 6, 2015
9d3ebaa
final(?) adjustments
xithan Oct 6, 2015
79d3208
hound style updates
xithan Oct 6, 2015
1cec401
seed update
xithan Oct 6, 2015
3ec0850
Merge remote-tracking branch 'wagn/master' into listedby
xithan Oct 6, 2015
b1d53b5
hound
xithan Oct 6, 2015
6f66c3a
:dog:
xithan Oct 6, 2015
3a486e7
ruby-style: turn "unnecessary spacing" off
xithan Oct 7, 2015
66977a5
:dog:
xithan Oct 7, 2015
4a2b2b0
fixed phase_method API
xithan Oct 7, 2015
4590c7b
:dog:
xithan Oct 7, 2015
6eeb5b2
another phase_method fix
xithan Oct 7, 2015
69c51cb
:dog:
xithan Oct 7, 2015
5d1b178
fetch.rb: refactor #fetch
xithan Oct 7, 2015
d7bd5c5
phase fixes
xithan Oct 7, 2015
e676aac
lock selenium-webdriver gem to 2.47
xithan Oct 8, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .codeclimate.yml
@@ -0,0 +1,7 @@
languages:
Ruby: true
JavaScript: true
PHP: false
Python: false
exclude_paths:
- "wagn/rails/assets"
1 change: 1 addition & 0 deletions .rubocop.yml
@@ -0,0 +1 @@
inherit_from: .ruby-style.yml
24 changes: 12 additions & 12 deletions .ruby-style.yml
Expand Up @@ -102,14 +102,14 @@ Style/CollectionMethods:
PreferredMethods:
collect: map
collect!: map!
find: detect
detect: find
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice thing about detect is that you wouldn't confuse it with ActiveRecord#find...

find_all: select
reduce: inject
Style/CommentAnnotation:
Description: Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK,
REVIEW).
StyleGuide: https://github.com/bbatsov/ruby-style-guide#annotate-keywords
Enabled: false
Enabled: true
Keywords:
- TODO
- FIXME
Expand All @@ -120,7 +120,7 @@ Style/DotPosition:
Description: Checks the position of the dot in multi-line method calls.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
Enabled: true
EnforcedStyle: trailing
EnforcedStyle: leading
SupportedStyles:
- leading
- trailing
Expand Down Expand Up @@ -154,7 +154,7 @@ Style/Encoding:
Description: Use UTF-8 as the source file encoding.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#utf-8
Enabled: false
EnforcedStyle: always
EnforcedStyle: when_needed
SupportedStyles:
- when_needed
- always
Expand Down Expand Up @@ -196,7 +196,7 @@ Style/GlobalVars:
Style/GuardClause:
Description: Check for conditionals that can be replaced with guard clauses
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
Enabled: false
Enabled: true
MinBodyLength: 1
Style/HashSyntax:
Description: 'Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a =>
Expand Down Expand Up @@ -250,7 +250,7 @@ Style/MethodDefParentheses:
Description: Checks if the method definitions have or don't have parentheses.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens
Enabled: true
EnforcedStyle: require_parentheses
EnforcedStyle: require_no_parentheses
SupportedStyles:
- require_parentheses
- require_no_parentheses
Expand Down Expand Up @@ -330,7 +330,7 @@ Style/RegexpLiteral:
characters. Use %r only for regular expressions matching more than `MaxSlashes`
'/' character.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-r
Enabled: false
Enabled: true
MaxSlashes: 1
Style/Semicolon:
Description: Don't use semicolons to terminate expressions.
Expand Down Expand Up @@ -390,7 +390,7 @@ Style/SpaceAroundEqualsInParameterDefault:
or don't have surrounding space depending on configuration.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-around-equals
Enabled: true
EnforcedStyle: space
EnforcedStyle: no_space
SupportedStyles:
- space
- no_space
Expand Down Expand Up @@ -518,9 +518,9 @@ Metrics/LineLength:
Metrics/MethodLength:
Description: Avoid methods longer than 10 lines of code.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
Enabled: false
Enabled: true
CountComments: false
Max: 10
Max: 15
Metrics/ParameterLists:
Description: Avoid parameter lists longer than three or four parameters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
Expand All @@ -535,7 +535,7 @@ Metrics/PerceivedComplexity:
Lint/AssignmentInCondition:
Description: Don't use assignment in conditions.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
Enabled: false
Enabled: true
AllowSafeAssignment: true
Lint/EndAlignment:
Description: Align ends correctly.
Expand Down Expand Up @@ -606,7 +606,7 @@ Style/SymbolArray:
Enabled: false
Style/ExtraSpacing:
Description: Do not use unnecessary spacing.
Enabled: true
Enabled: false
Style/AccessorMethodName:
Description: Check the naming of accessor methods for get_/set_.
Enabled: false
Expand Down
Expand Up @@ -13,7 +13,6 @@ def up
%w{bootstrap_default cerulean cosmo cyborg darkly flatly journal lumen paper readable sandstone simplex slate spacelab superhero united yeti }.each do |theme_name|
path = data_path "themes/#{theme_name}"
theme = Card.fetch "#{theme_name} skin"

if theme
theme.update_attributes! type_id: Card::SkinID, content: "[[themeless bootstrap skin]]\n[[+bootswatch theme]]", subcards: {
"+variables" => {type_id: Card::ScssID, content: File.read(File.join path, '_variables.scss')},
Expand Down
21 changes: 21 additions & 0 deletions card/db/migrate_core_cards/20150708224756_add_list_cards.rb
@@ -0,0 +1,21 @@
# -*- encoding : utf-8 -*-

class AddListCards < Card::CoreMigration
def up
Card.create! name: 'List', type_code: :cardtype, codename: :list
Card.create! name: 'Listed by',
type_code: :cardtype, codename: :listed_by
Card.create! name: '*cached count', codename: :cached_count,
subcards: {
'+*right+*update'=>'[[Administrator]]',
'+*right+*create'=>'[[Administrator]]',
'+*right+*delete'=>'[[Administrator]]'
}
Card.create! name: '*cached content', codename: :cached_content,
subcards: {
'+*right+*update'=>'[[Administrator]]',
'+*right+*create'=>'[[Administrator]]',
'+*right+*delete'=>'[[Administrator]]'
}
end
end
2 changes: 1 addition & 1 deletion card/db/seed
Submodule seed updated from be14cb to 797dce
3 changes: 2 additions & 1 deletion card/lib/card.rb
Expand Up @@ -32,6 +32,7 @@ def self.serializable_attr_accessor *args
require_dependency 'card/act'
require_dependency 'card/change'
require_dependency 'card/reference'
require_dependency 'card/subcards'
require_dependency 'card/view_cache'

has_many :references_from, class_name: :Reference, foreign_key: :referee_id
Expand All @@ -43,7 +44,7 @@ def self.serializable_attr_accessor *args
cattr_accessor :set_patterns, :error_codes, :serializable_attributes, :set_specific_attributes
@@set_patterns, @@error_codes = [], {}

serializable_attr_accessor :action, :supercard, :current_act, :current_action,
serializable_attr_accessor :action, :supercard, :superleft, :current_act, :current_action,
:comment, :comment_author, # obviated soon
:update_referencers, # wrong mechanism for this
:update_all_users, # if the above is wrong then this one too
Expand Down
75 changes: 39 additions & 36 deletions card/lib/card/auth.rb
Expand Up @@ -2,30 +2,30 @@

class Card
module Auth
@@as_card = @@as_id = @@current_id = @@current = @@simulating_setup_need = nil
@@as_card = @@as_id = @@current_id = @@current = nil
@@simulating_setup_need = nil

NON_CREATEABLE_TYPES = %w{ signup setting set } # NEED API
NEED_SETUP_KEY = 'NEED_SETUP'
SETUP_COMPLETED_KEY = 'SETUP_COMPLETED'

#after_save :reset_instance_cache
# after_save :reset_instance_cache

class << self

# Authenticates a user by their login name and unencrypted password.
def authenticate email, password
accounted = Auth[ email ]
if accounted and account = accounted.account and account.active?
if Card.config.no_authentication or password_authenticated?( account, password.strip )
accounted = Auth[email]
if accounted && (account = accounted.account) && account.active?
if Card.config.no_authentication ||
password_authenticated?(account, password.strip)
accounted.id
end
end
end

def password_authenticated? account, password
account.password == encrypt( password, account.salt )
account.password == encrypt(password, account.salt)
end


# Encrypts some data with the salt.
def encrypt password, salt
Digest::SHA1.hexdigest "#{salt}--#{password}--"
Expand All @@ -34,9 +34,11 @@ def encrypt password, salt
# find accounted by email
def [] email
Auth.as_bot do
Card.search( right_plus: [
{id: Card::AccountID},
{right_plus: [{id: Card::EmailID},{ content: email.strip.downcase }]}
Card.search(right_plus: [
{ id: Card::AccountID },
{ right_plus: [
{ id: Card::EmailID }, { content: email.strip.downcase }
] }
]).first
end
end
Expand All @@ -53,7 +55,7 @@ def session
def set_current_from_session
self.current_id =
if session
if card_id=session[:user] and Card.exists? card_id
if (card_id = session[:user]) && Card.exists?(card_id)
card_id
else
session[:user] = nil
Expand Down Expand Up @@ -81,12 +83,9 @@ def current_id= card_id

def get_user_id user
case user
when NilClass; nil
when Card ; user.id
when Integer ; user
else
user = user.to_s
Card::Codename[user] or (cd=Card[user] and cd.id)
when NilClass then nil
when Card then user.id
else Card.fetch_id(user)
end
end

Expand Down Expand Up @@ -118,7 +117,7 @@ def as_id
end

def as_card
if @@as_card and @@as_card.id == as_id
if @@as_card && @@as_card.id == as_id
@@as_card
else
@@as_card = Card[as_id]
Expand All @@ -130,43 +129,48 @@ def signed_in?
end

def needs_setup?
test = Card.cache.read NEED_SETUP_KEY
!test.nil? ? test : begin
@@simulating_setup_need or Card.cache.write( NEED_SETUP_KEY, (account_count < 3) ) # 3, because
@@simulating_setup_need || !Card.cache.fetch(SETUP_COMPLETED_KEY) do
# every deck starts with WagnBot and Anonymous account
account_count > 2
end
end

def simulate_setup_need! mode=true
def simulate_setup_need! mode = true
@@simulating_setup_need = mode
Card.cache.write NEED_SETUP_KEY, nil
end

def instant_account_activation
simulate_setup_need!
yield
ensure
simulate_setup_need! false
end

def always_ok?
#warn Rails.logger.warn("aok? #{as_id}, #{as_id&&Card[as_id].id}")
# warn Rails.logger.warn("aok? #{as_id}, #{as_id&&Card[as_id].id}")
return false unless usr_id = as_id
return true if usr_id == Card::WagnBotID #cannot disable
return true if usr_id == Card::WagnBotID # cannot disable

always = Card.cache.read('ALWAYS') || {}
#warn(Rails.logger.warn "Auth.always_ok? #{usr_id}")
# warn(Rails.logger.warn "Auth.always_ok? #{usr_id}")
if always[usr_id].nil?
always = always.dup if always.frozen?
always[usr_id] = !!Card[usr_id].all_roles.detect{|r|r==Card::AdministratorID}
#warn(Rails.logger.warn "update always hash #{always[usr_id]}, #{always.inspect}")
always[usr_id] = !!Card[usr_id].all_roles.detect { |r| r == Card::AdministratorID }
# warn(Rails.logger.warn "update always hash #{always[usr_id]}, #{always.inspect}")
Card.cache.write 'ALWAYS', always
end
#warn Rails.logger.warn("aok? #{usr_id}, #{always[usr_id]}")
# warn Rails.logger.warn("aok? #{usr_id}, #{always[usr_id]}")
always[usr_id]
end
# PERMISSIONS


def createable_types
type_names = Auth.as_bot do
Card.search type: Card::CardtypeID, return: :name, not: { codename: ['in'] + NON_CREATEABLE_TYPES }
Card.search type: Card::CardtypeID, return: :name,
not: { codename: ['in'] + NON_CREATEABLE_TYPES }
end
type_names.reject do |name|
!Card.new( type: name ).ok? :create
type_names.select do |name|
Card.new(type: name).ok? :create
end.sort
end

Expand All @@ -175,7 +179,6 @@ def createable_types
def account_count
as_bot { Card.count_by_wql right: Card[:account].name }
end

end
end
end
6 changes: 5 additions & 1 deletion card/lib/card/cache.rb
Expand Up @@ -182,6 +182,10 @@ def delete key
@local.delete key
end

def delete_local key
@local.delete key
end

def dump
p "dumping local...."
@local.each do |k, v|
Expand Down Expand Up @@ -211,7 +215,7 @@ def reset_local
end

def exist? key
@local.has_key?(key) || @store.exist?(key)
@local.has_key?(key) || (@store && @store.exist?(key))
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions card/lib/card/codename.rb
Expand Up @@ -29,10 +29,10 @@ def reset_cache
def bootdata hash
@@codehash = hash
end


private

def cache
Card::Cache[Codename]
end
Expand All @@ -53,10 +53,10 @@ def load_hash
end
end
end

end


def self.const_missing const
if const.to_s =~ /^([A-Z]\S*)ID$/ and code=$1.underscore.to_sym
if card_id = Codename[code]
Expand All @@ -68,5 +68,5 @@ def self.const_missing const
super
end
end

end