Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accounts association to the project model #1535

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions model/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Project < Sequel::Model
one_to_many :usage_alerts
one_to_many :github_installations

many_to_many :accounts, join_table: AccessTag.table_name, left_key: :project_id, right_key: :hyper_tag_id
many_to_many :vms, join_table: AccessTag.table_name, left_key: :project_id, right_key: :hyper_tag_id
many_to_many :minio_clusters, join_table: AccessTag.table_name, left_key: :project_id, right_key: :hyper_tag_id
many_to_many :private_subnets, join_table: AccessTag.table_name, left_key: :project_id, right_key: :hyper_tag_id
Expand All @@ -31,10 +32,6 @@ def hyper_tag_name(project = nil)

include Authorization::TaggableMethods

def user_ids
access_tags_dataset.where(hyper_tag_table: Account.table_name.to_s).select_map(:hyper_tag_id)
end

def has_valid_payment_method?
return true unless Config.stripe_secret_key
!!billing_info&.payment_methods&.any?
Expand Down
2 changes: 1 addition & 1 deletion routes/api/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CloverApi
r.halt
end

unless @project.user_ids.include?(@current_user.id)
unless @project.accounts.any? { _1.id == @current_user.id }
fail Authorization::Unauthorized
end

Expand Down
2 changes: 1 addition & 1 deletion routes/web/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CloverWeb
r.halt
end

unless @project.user_ids.include?(@current_user.id)
unless @project.accounts.any? { _1.id == @current_user.id }
fail Authorization::Unauthorized
end

Expand Down
5 changes: 2 additions & 3 deletions routes/web/project/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class CloverWeb
@serializer = Serializers::Web::Account

r.get true do
users_with_hyper_tag = @project.user_ids
@users = serialize(Account.where(id: users_with_hyper_tag).all)
@users = serialize(@project.accounts)

view "project/user"
end
Expand Down Expand Up @@ -41,7 +40,7 @@ class CloverWeb
end

r.delete true do
unless @project.user_ids.count > 1
unless @project.accounts.count > 1
response.status = 400
return {message: "You can't remove the last user from '#{@project.name}' project. Delete project instead."}.to_json
end
Expand Down