Base solution for your next web application
Open Closed

Need help for using OrganizationUnit #5306


User avatar
0
hitaspdotnet created

Hi, I want try to use OU in my project I can't understand ABP original documents. In ABP docs author just focused on getting entities in OUs. So how the entity sets in OU/ChildOU?

In my case, I have a root OU named 'Spaces' and that contains grouped users for example 'Management Team', 'Customer Relation', 'Developers' , etc. The spaces has child spaces for example 'Management Team contains Owners|Moderators' In last, I have entities that should belongs to an Space/ChildSpace and that entities must be available just for Space/ChildSpace users. For example 'Blogs', 'News', 'Files', etc.

I have try this case before reading Abp OU docs by:

  1. Creating Space class
public class Space : FullAuditedEntity, 
        IMustHaveTenant,
        IMultiLingualEntity<SpaceTranslation>
    {
        private ICollection<UserGroup> _userGroups;

        public int TenantId { get; set; }

        public int? ParentId { get; set; }

        public virtual string CompanyName { get; set; }
  
        public virtual string CompanyAddress { get; set; }

        public virtual string CompanyPhoneNumber { get; set; }

        public virtual bool IsPrivate { get; set; }

        public virtual long OwnerId { get; set; }

        public virtual ICollection<UserGroup> UserGroups
        {
            get => _userGroups ?? (_userGroups= new List<UserGroup>());
            protected set => _userGroups= value;
        }

        public ICollection<SpaceTranslation> Translations { get; set; }
    }
  1. Creating Space Contents (Blogs as sample)
public class BlogPost : CreationAuditedEntity,
        IMustHaveTenant, 
        IMultiLingualEntity<BlogPostTranslation>
    {
        private ICollection<BlogComment> _blogComments;

        public int TenantId { get; set; }

        public virtual bool AllowComments { get; set; }

        public virtual string Tags { get; set; }

        public virtual DateTime? StartDateUtc { get; set; }

        public virtual DateTime? EndDateUtc { get; set; }

        public virtual string MetaKeywords { get; set; }

        public virtual string MetaDescription { get; set; }

        public virtual string MetaTitle { get; set; }

        public virtual int SpaceId { get; set; }

        public virtual ICollection<BlogComment> BlogComments
        {
            get => _blogComments ?? (_blogComments = new List<BlogComment>());
            protected set => _blogComments = value;
        }

        public virtual ICollection<BlogPostTranslation> Translations { get; set; }

I think it's can be easier using ABP OU feature, How can you doing this by using Abp OrganizationUnit? Please if possible help me with sample code. Thanks in advance :? :(


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @csbeginner ABP has defined

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Organizations/IMayHaveOrganizationUnit.cs">https://github.com/aspnetboilerplate/as ... ionUnit.cs</a> and <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Organizations/IMustHaveOrganizationUnit.cs">https://github.com/aspnetboilerplate/as ... ionUnit.cs</a>

    interfaces to standardize the usage or OrganizationUnitId but those interfaces are not used in dynamic filtering.

    So, you can derive your entities from one of those interfaces and implement an OrganizationUnit filter similar to IMayHaveTenant or IMustHaveTenant.

  • User Avatar
    0
    hitaspdotnet created

    <cite>ismcagdas: </cite> @csbeginner ABP has defined

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Organizations/IMayHaveOrganizationUnit.cs">https://github.com/aspnetboilerplate/as ... ionUnit.cs</a> and <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Organizations/IMustHaveOrganizationUnit.cs">https://github.com/aspnetboilerplate/as ... ionUnit.cs</a>

    interfaces to standardize the usage or OrganizationUnitId but those interfaces are not used in dynamic filtering.

    So, you can derive your entities from one of those interfaces and implement an OrganizationUnit filter similar to IMayHaveTenant or IMustHaveTenant.

    Thanks for reply. My question is 'How to have CRUD entity service for an entity with not-nullable organization unit, when that entity's organization unit had child/parents?'

    I can't understand the OU.Code section, How Abp mapping tree of OU at CURD request? We should pass OU.Code or OU.Id from our controllers in write scenarios?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @csbeginner ABP and AspNet Zero don't provide any built in structure to use OUs with other entities.

    So, in order to understnad your case better, I have a few questions.

    1. Which entity you want to add non-nullable OrganizationUnitId ?
    2. How would oyu like to associate this entity with an OU ? Do you want users to select it on the UI ? Or do you want to associate it with the currently logged in user's OU ?
  • User Avatar
    0
    hitaspdotnet created

    <cite>ismcagdas: </cite>

    1. Which entity you want to add non-nullable OrganizationUnitId ?
    2. How would oyu like to associate this entity with an OU ? Do you want users to select it on the UI ? Or do you want to associate it with the currently logged in user's OU ?

    Hi,

    1. All entities each of which has SpaceId property (OR Space's contents).

    2. Since each user may be a member of multi spaces, so it must be selected in the UI

    I just need an 'Create/Update entity in OU' example so I can understand the ABP OU feature.

    For example: We have a root OU named as 'MyRootOu' with code '00001' 'MyRootOu' has child named as 'MyRootOuChild' with code '00001.00001'

    Now, we have a entity named as 'Blog' with not-nullable Ou Id, When a user wants to create a new Blog in 'MyRootOuChild' , what we need and how it possible in the 'BlogAppService'?

    1. Is the Ou ID sufficient?
    2. Given the example above, where is the best use of 'myRootOuChild.Code'? // I can't understand the CODE section of a OU

    Thanks in advance @ismcagdas

  • User Avatar
    0
    ismcagdas created
    Support Team

    @csbeginner you can use OUId for your relation. The code for organization unit ('00001.00001' or '00001') ise used to order OU records and used to find parent/children of an OU easily.

    If you don't use a code for each OU like we did, it is hard to order OUs and it is hard to find parent or children of an OU.