sylae / ligrev

XMPP MUC Utility bot
GNU General Public License v3.0
2 stars 1 forks source link

Permissions support #38

Closed sylae closed 8 years ago

sylae commented 8 years ago

Currently we allow anyone to do anything, with a couple hard-coded exceptions. Obviously this is not ideal.

$config['permissions']['example-permission'] = true; // global default
$config['rooms']['lounge@conference.calref.net']['permissions']['example-permission'] = false; // room override

$config['permissions']['sylae@calref.net']['admin-example-permission'] = true; // user override
$config['rooms']['rp@conference.calref.net']['permissions']['sylae@calref.net']['rig-dice'] = false; // don't cheat

Permission masks should be applied in the following order:

  1. default to false.
  2. Apply global default permission
  3. Apply room-specific permission
  4. Apply user permission
  5. Apply user-room permission

Something like this should be a good effect:

$effective_perms = array_merge(
  $this->c['permissions'],
  (array_key_exists('permissions', $this->c['rooms'][$room]) ?
    $this->c['rooms'][$room]['permissions'] :
    array()
  ),
  (array_key_exists($user_jid->bare, $this->c['permissions']) ?
    $this->c['permissions'][$user_jid->bare] :
    array()
  ),
  (array_key_exists('permissions', $this->c['rooms'][$room] &&
   array_key_exists($user_jid->bare, $this->c['rooms'][$room]['permissions']) ?
    $this->c['rooms'][$room]['permissions'][$user_jid->bare] :
    array()
  )
);

boy, that's a fun bit of code :|