Files
ubicloud/model/account.rb
Enes Cakir 140e2930d3 Create new project with managed admin policy instead of custom policy
When we create a new project, we also create an access policy granting
all permissions to the current user. With the introduction of managed
policies, we can now apply the managed admin policy, eliminating the
need to create a custom policy with full permissions.

The current user will be admin for the newly created project.

Most changes are within the test, as we expect the project have a custom
admin policy.
2024-10-10 16:27:55 +03:00

30 lines
788 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class Account < Sequel::Model(:accounts)
include ResourceMethods
include Authorization::HyperTagMethods
def hyper_tag_name(project = nil)
"user/#{email}"
end
include Authorization::TaggableMethods
def create_project_with_default_policy(name, default_policy: Authorization::ManagedPolicy::Admin)
project = Project.create_with_id(name: name)
project.associate_with_project(project)
associate_with_project(project)
default_policy&.apply(project, [self])
project
end
def suspend
update(suspended_at: Time.now)
DB[:account_active_session_keys].where(account_id: id).delete(force: true)
projects.each { _1.billing_info&.payment_methods_dataset&.update(fraud: true) }
end
end