Commit e1cdd603 authored by Philipp Hörist's avatar Philipp Hörist

MUC: Improve change affiliation logic

parent 921594c1
......@@ -1665,10 +1665,21 @@ def get_alternative_venue(error):
return uri.data['jid']
def is_affiliation_change_allowed(self_contact, contact):
if self_contact.affiliation < Affiliation.ADMIN:
def is_affiliation_change_allowed(self_contact, contact, target_aff):
if contact.affiliation.value == target_aff:
# Contact has already the target affiliation
return False
return self_contact.affiliation >= contact.affiliation
if self_contact.affiliation.is_owner:
return True
if not self_contact.affiliation.is_admin:
return False
if target_aff in ('admin', 'owner'):
# Admin cant edit admin/owner list
return False
return self_contact.affiliation > contact.affiliation
def is_role_change_allowed(self_contact, contact):
......
......@@ -897,7 +897,7 @@ def get_groupchat_roster_menu(account, control_id, self_contact, contact):
item = Gtk.MenuItem(label=_('Ban'))
action = 'win.ban-%s::%s' % (control_id, contact.jid or '')
if is_affiliation_change_allowed(self_contact, contact):
if is_affiliation_change_allowed(self_contact, contact, 'outcast'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
......@@ -908,8 +908,7 @@ def get_groupchat_roster_menu(account, control_id, self_contact, contact):
item = Gtk.MenuItem(label=_('Make Owner'))
action = 'win.change-affiliation-%s(["%s", "owner"])' % (control_id,
contact.jid)
if (is_affiliation_change_allowed(self_contact, contact) and
not contact.affiliation.is_owner):
if is_affiliation_change_allowed(self_contact, contact, 'owner'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
......@@ -918,8 +917,7 @@ def get_groupchat_roster_menu(account, control_id, self_contact, contact):
item = Gtk.MenuItem(label=_('Make Admin'))
action = 'win.change-affiliation-%s(["%s", "admin"])' % (control_id,
contact.jid)
if (is_affiliation_change_allowed(self_contact, contact) and
not contact.affiliation.is_admin):
if is_affiliation_change_allowed(self_contact, contact, 'admin'):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
......@@ -936,8 +934,7 @@ def get_groupchat_roster_menu(account, control_id, self_contact, contact):
action = 'win.change-affiliation-%s(["%s", "%s"])' % (control_id,
contact.jid,
affiliation)
if (is_affiliation_change_allowed(self_contact, contact) and
contact.affiliation.value != affiliation):
if is_affiliation_change_allowed(self_contact, contact, affiliation):
item.set_detailed_action_name(action)
else:
item.set_sensitive(False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment