Skip to content

Commit

Permalink
Fix create and delete room permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
smpallen99 committed Mar 10, 2018
1 parent 7c13e9b commit 5c67753
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* Update rooms after admin delete room
* UCx-3798 - Add owner role when creating a room.
* Add fix_owner_roles release task
* Fix administration permissions

### Bug Fixes

* Off-line users now see alerts generated while off-line when logging back in
* Fixed hiding unread-bar when last message not visible on browser focus.
* Close open subscriptions when logging out or closing browser.
* Fix administration permissions
* Fix create and delete room permission checks


## 0.3.1 (2018-01-05)
Expand Down
15 changes: 6 additions & 9 deletions plugins/ucc_chat/lib/ucc_chat/models/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defmodule UccChat.Channel do

require Logger


def update(channel, user, params) do
# Logger.warn "update params: " <> inspect(params)
channel
Expand Down Expand Up @@ -64,7 +63,7 @@ defmodule UccChat.Channel do
end

defp can_delete?(channel, user) do
Permissions.has_permission? user, "delete-" <> Permissions.room_type(channel.type)
Permissions.has_permission? user, "delete-" <> Permissions.room_type(channel.type), channel.id
end

def changeset(user, params) do
Expand Down Expand Up @@ -117,27 +116,25 @@ defmodule UccChat.Channel do
true
end


def has_permission?(user, %{id: nil} = data, changes) do
Permissions.has_permission?(user, type_permission("create", changes[:type] || 0))
end

def has_permission?(user, data, changes) do
# Logger.warn "changes: " <> inspect(changes)
changes
|> Enum.all?(fn {field, value} ->
has_permission?(user, data, field, value)
end)
end

defp has_permission?(user, %{id: channel_id, type: _type}, _field, _value) do
# Logger.warn "{field, value}: " <> inspect({field, value})
# permission = type_permission("edit", type)
Permissions.has_permission?(user, "edit-room", channel_id)
# false
end

defp has_permission?(_user, %{id: _channel_id}, _field, _value) do
false
end
# defp has_permission?(user, %{type: 1}), do: Permissions.has_permission?(user, "create-p")
# defp has_permission?(user, %{type: 2}), do: Permissions.has_permission?(user, "create-d")
# defp has_permission?(user, _), do: Permissions.has_permission?(user, "create-c")

def total_rooms do
from c in @schema, select: count(c.id)
Expand Down
5 changes: 3 additions & 2 deletions plugins/ucc_chat/lib/ucc_chat/services/channel_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,10 @@ defmodule UccChat.ChannelService do
channel_command(socket, :join, channel, user_id, channel_id)

{:ok, ~g"Channel created successfully"}
{:error, _} ->
{:error, _, changeset} ->
message = UccChatWeb.SharedView.format_errors(changeset)
{:error,
gettext("There was a problem creating #%{name} channel.", name: name)}
gettext("There was a problem creating #%{name} channel. ", name: name) <> message}
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
= if field[:visible] do
= flex_form_line(f, field, @editing, @channel_type)

= if has_permission? @current_user, "delete-" <> Permissions.room_type(@channel_type) do
= if has_permission? @current_user, "delete-" <> Permissions.room_type(@channel_type), @changeset.data.id do
nav
button type="submit" style="display:none"
button.button.danger.delete(title="#{~g(Delete)}" rebel-click="flex_form_delete")
Expand Down

0 comments on commit 5c67753

Please sign in to comment.