liquid_feedback_frontend

diff model/member.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents 77dc363fa0be
children faaf9ec3e09c
line diff
     1.1 --- a/model/member.lua	Thu Jun 23 03:30:57 2016 +0200
     1.2 +++ b/model/member.lua	Sun Jul 15 14:07:29 2018 +0200
     1.3 @@ -166,6 +166,24 @@
     1.4  }
     1.5  
     1.6  Member:add_reference{
     1.7 +  mode          = '11',
     1.8 +  to            = "MemberProfile",
     1.9 +  this_key      = 'id',
    1.10 +  that_key      = 'member_id',
    1.11 +  ref           = 'profile',
    1.12 +  back_ref      = 'member'
    1.13 +}
    1.14 +
    1.15 +Member:add_reference{
    1.16 +  mode          = '11',
    1.17 +  to            = "MemberSettings",
    1.18 +  this_key      = 'id',
    1.19 +  that_key      = 'member_id',
    1.20 +  ref           = 'settings',
    1.21 +  back_ref      = 'member'
    1.22 +}
    1.23 +
    1.24 +Member:add_reference{
    1.25    mode                  = 'mm',
    1.26    to                    = "Member",
    1.27    this_key              = 'id',
    1.28 @@ -242,8 +260,6 @@
    1.29    ref                   = 'supported_initiatives'
    1.30  }
    1.31  
    1.32 -model.has_rendered_content(Member, RenderedMemberStatement, "statement")
    1.33 -
    1.34  function Member:build_selector(args)
    1.35    local selector = self:new_selector()
    1.36    if args.active ~= nil then
    1.37 @@ -531,6 +547,12 @@
    1.38    
    1.39  end
    1.40  
    1.41 +function Member:by_ids(ids)
    1.42 +  local selector = self:new_selector()
    1.43 +  selector:add_where{'"id" IN ($)', { ids } }
    1.44 +  return selector:exec()
    1.45 +end
    1.46 +
    1.47  function Member:by_login(login)
    1.48    local selector = self:new_selector()
    1.49    selector:add_where{'"login" = ?', login }
    1.50 @@ -589,19 +611,23 @@
    1.51    
    1.52    local subject = subject
    1.53    local content
    1.54 -  
    1.55 +  local baseurl = request.get_absolute_baseurl() .. "index/register.html"
    1.56 +  local url = baseurl .. "?skip=1&code=" .. self.invite_code
    1.57    if template_file then
    1.58      local fh = io.open(template_file, "r")
    1.59      content = fh:read("*a")
    1.60 -    content = (content:gsub("#{invite_code}", self.invite_code))
    1.61 +    content = content:gsub("#{url}", url):gsub("#{baseurl}", baseurl):gsub("#{code}", self.invite_code)
    1.62 +  elseif config.invitation_mail then
    1.63 +    subject = config.invitation_mail.subject
    1.64 +    content = config.invitation_mail.content:gsub("#{url}", url):gsub("#{baseurl}", baseurl):gsub("#{code}", self.invite_code)
    1.65    else
    1.66      subject = config.mail_subject_prefix .. _"Invitation to LiquidFeedback"
    1.67      content = slot.use_temporary(function()
    1.68        slot.put(_"Hello\n\n")
    1.69        slot.put(_"You are invited to LiquidFeedback. To register please click the following link:\n\n")
    1.70 -      slot.put(request.get_absolute_baseurl() .. "index/register.html?invite=" .. self.invite_code .. "\n\n")
    1.71 +      slot.put(url .. "\n\n")
    1.72        slot.put(_"If this link is not working, please open following url in your web browser:\n\n")
    1.73 -      slot.put(request.get_absolute_baseurl() .. "index/register.html\n\n")
    1.74 +      slot.put(baseurl .. "\n\n")
    1.75        slot.put(_"On that page please enter the invite key:\n\n")
    1.76        slot.put(self.invite_code .. "\n\n")
    1.77      end)
    1.78 @@ -738,7 +764,33 @@
    1.79    end
    1.80  end
    1.81  
    1.82 -function Member.object:has_voting_right_for_unit_id(unit_id)
    1.83 +local function populate_units_with_initiative_right_hash(self)
    1.84 +  if not self.__units_with_initiative_right_hash then
    1.85 +    local privileges = Privilege:new_selector()
    1.86 +      :add_where{ "member_id = ?", self.id }
    1.87 +      :add_where("initiative_right")
    1.88 +      :exec()
    1.89 +    self.__units_with_initiative_right_hash = {}
    1.90 +    for i, privilege in ipairs(privileges) do
    1.91 +      self.__units_with_initiative_right_hash[privilege.unit_id] = true
    1.92 +    end
    1.93 +  end
    1.94 +end
    1.95 +
    1.96 +function Member.object:has_initiative_right_for_unit_id(unit_id)
    1.97 +  populate_units_with_initiative_right_hash(self)
    1.98 +  return self.__units_with_initiative_right_hash[unit_id] and true or false
    1.99 +end
   1.100 +
   1.101 +function Member.object_get:has_initiative_right()
   1.102 +  populate_units_with_initiative_right_hash(self)
   1.103 +  for k, v in pairs(self.__units_with_initiative_right_hash) do
   1.104 +    return true
   1.105 +  end
   1.106 +  return false
   1.107 +end
   1.108 +
   1.109 +local function populate_units_with_voting_right_hash(self)
   1.110    if not self.__units_with_voting_right_hash then
   1.111      local privileges = Privilege:new_selector()
   1.112        :add_where{ "member_id = ?", self.id }
   1.113 @@ -749,6 +801,18 @@
   1.114        self.__units_with_voting_right_hash[privilege.unit_id] = true
   1.115      end
   1.116    end
   1.117 +end
   1.118 +
   1.119 +function Member.object_get:has_voting_right()
   1.120 +  populate_units_with_voting_right_hash(self)
   1.121 +  for k, v in pairs(self.__units_with_voting_right_hash) do
   1.122 +    return true
   1.123 +  end
   1.124 +  return false
   1.125 +end
   1.126 +
   1.127 +function Member.object:has_voting_right_for_unit_id(unit_id)
   1.128 +  populate_units_with_voting_right_hash(self)
   1.129    return self.__units_with_voting_right_hash[unit_id] and true or false
   1.130  end
   1.131  
   1.132 @@ -778,3 +842,13 @@
   1.133  function Member.object:delete()
   1.134    db:query{ "SELECT delete_member(?)", self.id }
   1.135  end
   1.136 +
   1.137 +function Member.object_get:display_name()
   1.138 +  if self.identification then
   1.139 +    return self.identification
   1.140 +  elseif self.name then
   1.141 +    return self.name
   1.142 +  else
   1.143 +    return "Member #" .. self.id
   1.144 +  end
   1.145 +end

Impressum / About Us