Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed May 22, 2024
1 parent 070fe4f commit ec056a3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ def self.model

validate :name_select_included
validate :existing_selects
validate :user_is_logged_in
validate :allowed_to_modify_private_query
validate :allowed_to_modify_public_query

protected

def user_is_logged_in
if !user.logged?
errors.add :base, :error_unauthorized
end
end

def allowed_to_modify_private_query
return if model.public?

Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
nonexistent: "The column '%{column}' does not exist."
format: "%{message}"
group_by_hierarchies_exclusive: "is mutually exclusive with group by '%{group_by}'. You cannot activate both."
can_only_be_modified_by_owner: "The query can only be modified by its owner."
need_permission_to_modify_public_query: "You cannot modify a public query."
filters:
custom_fields:
inexistent: "There is no custom field for the filter."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,51 @@
context "if the user is not the current user" do
let(:query_user) { build_stubbed(:user) }

it_behaves_like "contract is invalid", base: :error_unauthorized
it_behaves_like "contract is invalid", base: :can_only_be_modified_by_owner
end

context "if the list is public and the editing user has the permission" do
let(:query_user) { build_stubbed(:user) }

before do
query.change_by_system do
query.public = true
end

mock_permissions_for(current_user) do |mock|
mock.allow_globally :manage_public_project_queries
end
end

it_behaves_like "contract is valid"
end

context "if the list is public and the editing user does not have the permission" do
let(:query_user) { build_stubbed(:user) }

before do
query.change_by_system do
query.public = true
end

mock_permissions_for(current_user, &:forbid_everything)
end

it_behaves_like "contract is invalid", base: :need_permission_to_modify_public_query
end

context "if the list is public and the editing user does not have the permission, even if they are the owner" do
let(:query_user) { current_user }

before do
query.change_by_system do
query.public = true
end

mock_permissions_for(current_user, &:forbid_everything)
end

it_behaves_like "contract is invalid", base: :need_permission_to_modify_public_query
end

context "if the user and the current user is anonymous" do
Expand Down

0 comments on commit ec056a3

Please sign in to comment.