Class: ODDB::State::Admin::Entity

Inherits:
Global show all
Defined in:
src/state/admin/entity.rb

Constant Summary

VIEW =
View::Admin::Entity

Constants inherited from Global

HOME_STATE, ZONE

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Method Summary (collapse)

Methods inherited from Global

#zone_navigation

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Method Details

- (Object) set_pass



112
113
114
# File 'src/state/admin/entity.rb', line 112

def set_pass
  update
end

- (Object) update



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'src/state/admin/entity.rb', line 12

def update
  mandatory = [:name]
  preferences = [:name_first, :name_last, :salutation, :address, :plz, :city]
  keys = mandatory + preferences + [ :valid_until, :yus_privileges,
    :yus_groups, :set_pass_1, :set_pass_2, :yus_association ]
  input = user_input(keys, mandatory)
  pass1 = nil
  begin
    pass1 = input[:set_pass_1]
    pass2 = input[:set_pass_2]
    if(pass1 || pass2)
      if(pass1 != pass2)
        err1 = create_error(:e_non_matching_set_pass, :set_pass_1, pass1)
        err2 = create_error(:e_non_matching_set_pass, :set_pass_2, pass2)
        @errors.store(:set_pass_1, err1)
        @errors.store(:set_pass_2, err2)
      end
    end
    unless(error?)
      name = @model.name
      if(@model.is_a?(Persistence::CreateItem))
        @model = @session.user.create_entity(input[:name])
      elsif(input[:name] != name)
        if mdl = @session.app.yus_model(name)
          mdl.users.collect! do |usr|
            if usr.yus_name == name
              YusStub.new input[:name]
            else
              usr
            end
          end
          mdl.odba_store
        end
        @session.user.rename(name, input[:name])
        name = input[:name]
        @model = @session.user.find_entity(name)
      end
      if(pass1)
        @session.user.set_password(name, pass1)
      end
      preferences.each { |pref|
        @session.user.set_entity_preference(name, pref, input[pref], 'global')
      }
      privs = input[:yus_privileges] || {}
      if((ass_str = input[:yus_association]) \
         && (ass_ptr = Persistence::Pointer.from_yus_privilege(ass_str)) \
         && (ass = ass_ptr.resolve(@session)))
        if(old = @session.app.yus_model(name))
          old.remove_user YusStub.new(@model.name)
          @session.user.revoke(name, 'edit', old.pointer.to_yus_privilege)
        end
        ass.add_user YusStub.new(@model.name)
        @session.user.grant(name, 'edit', ass_str)
        @session.user.set_entity_preference(name, 'association', ass.odba_id)
      elsif old = @session.app.yus_model(name)
        old.remove_user YusStub.new(@model.name)
        @session.user.revoke(name, 'edit', old.pointer.to_yus_privilege)
      end
      @session.valid_values(:yus_privileges).each { |privilege|
        action, key = privilege.split('|')
        if(@session.allowed?('grant', action))
          method = privs[privilege] ? :grant : :revoke
          @session.user.send(method, name, action, key)
        end
      }
      groups = input[:yus_groups] || {}
      @model.affiliations.each { |group| 
        unless(groups[group.name])
          @session.user.disaffiliate(name, group.name)
          if(group.name == 'PowerUser')
            @session.user.revoke(name, 'view', 'org.oddb')
          end
        end
      }
      groups.each { |groupname, value|
        @session.user.affiliate(name, groupname)
        time = if(date = input[:valid_until])
                 date = date.next
                 Time.local(date.year, date.month, date.day) - 1
               end
        if(groupname == 'PowerUser')
          @session.user.grant(name, 'view', 'org.oddb', time)
        end
      }
    end
  rescue Yus::DuplicateNameError => e
    @errors.store(:name, 
                  create_error(:e_duplicate_email, :name, name))
  rescue Yus::YusError => e
    puts e.class, e.message
    puts e.backtrace
    @errors.store(:yus_privileges, 
                  create_error(e.message, :e_yus_error, e.message))
  rescue Exception => e
    puts "something weird happened:"
    puts e.class, e.message
    puts e.backtrace
  end
  self
end