X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d6cc9d6e055974384be446f6da8218ff7da048ae..0561bd0c3c07257fd58ded6c7cfa5feeae97af57:/services/api/app/models/group.rb diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb index 9666257ea4..0dd2a73576 100644 --- a/services/api/app/models/group.rb +++ b/services/api/app/models/group.rb @@ -1,10 +1,44 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + +require 'can_be_an_owner' + class Group < ArvadosModel - include AssignUuid + include HasUuid include KindAndEtag include CommonApiTemplate + include CanBeAnOwner + after_create :invalidate_permissions_cache + after_update :maybe_invalidate_permissions_cache + before_create :assign_name api_accessible :user, extend: :common do |t| t.add :name + t.add :group_class t.add :description + t.add :writable_by end + + def maybe_invalidate_permissions_cache + if uuid_changed? or owner_uuid_changed? + # This can change users' permissions on other groups as well as + # this one. + invalidate_permissions_cache + end + end + + def invalidate_permissions_cache + # Ensure a new group can be accessed by the appropriate users + # immediately after being created. + User.invalidate_permissions_cache db_current_time.to_i + end + + def assign_name + if self.new_record? and (self.name.nil? or self.name.empty?) + self.name = self.uuid + end + true + end + end