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

Design doc for organizations #5958

Merged
merged 15 commits into from
Oct 23, 2019
148 changes: 148 additions & 0 deletions docs/development/design/organizations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
Organizations
=============

Currently we don't support organizations in the community site
(a way to group different projects),
we only support individual accounts.

Several integrations that we support like GitHub and Bitbucket have organizations,
where users group their repositories and manage them in groups rather than individually.

Why move organizations in the community site?
---------------------------------------------

We support organizations in the commercial site,
having no organizations in the community site makes the code maintenance difficult for Read the Docs developers.
Having organizations in the community site will make the differences between both more easy to manage.

Users from the community site can have organizations in external sites from where we import their projects
(like GitHub, Gitlab).
Currently users have all projects from different organizations in their account.
Having not a clear way to group/separate those.

There is also a product decision.
Supporting organizations only on code,
but enable the feature only on the commercial site.
agjohnson marked this conversation as resolved.
Show resolved Hide resolved

How are we going to support organizations?
------------------------------------------

Currently only users can own projects.
With organizations this is going to change to:
Users and organizations can own projects.

With this, the migration process would be straightforward for the community site.

For the commercial site we still have a decision.
Are we going to support users and organizations to own projects?
Or just organizations?
agjohnson marked this conversation as resolved.
Show resolved Hide resolved

What features of organizations are we going to support?
-------------------------------------------------------

We have the following features in the commercial site that we don't have on the community site:

- Owners
- Teams
- Permissions
- Subscriptions

Owners should be included to represent owners of the current organization.

Teams, this is also handy to manage access to different projects under the same organization.

Permissions,
currently we have two type of permissions for teams: admin and read only.
Read only permissions doesn't make sense in the community site since we only support public projects/versions
(we do support private versions now, but we are planning to remove those).
So, we should only support admin permissions for teams.
agjohnson marked this conversation as resolved.
Show resolved Hide resolved

Subscriptions, this is only valid for the corporate site,
since we don't charge for use in the community site.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have our Gold users map onto this, but I don't think it should be part of this migration.


How to migrate current projects
-------------------------------

Since we are not replacing the current implementation,
we don't need to migrate current projects from the community site nor from the corporate site.

How to migrate the organizations app
------------------------------------

The migration can be split in:

#. Remove/simplify code from the organizations app on the corporate site.
#. Isolate/separate models and code that isn't going to be moved.
#. Start by moving the models, managers, and figure out how to handle migrations.
#. Move the rest of the code as needed.
#. Activate organizations app on the community site.
#. Integrate the code from the community site to the new code.

We should start by removing unused features and dead code from the organizations in the corporate site,
and simplify existing code if possible (some of this was already done).
Another simplification that can be done is:
make the relationship between the models ``Organization`` and ``Project`` one to many
(currently many to many).

Isolate/separate the models to be moved from the ones that aren't going to be moved.
We should move the models that aren't going to me moved to another app.

- Plan
- PlanFeature
- Subscription

This app can be named *subscriptions*.
We can get around the table names and migrations by setting the explicitly the table name to ``organizations_<model>``,
and doing a fake migration.
Following suggestions in https://stackoverflow.com/questions/48860227/moving-multiple-models-from-one-django-app-to-another.
Code related to subscriptions should be moved out from the organizations app.

After that, it should be easier to move the organizations *app* (or part of it)
to the community site (and no changes to table names would be required).

We start by moving the models.

- Organization
- OrganizationOwner
- Team
- TeamInvite
- TeamMember

Migrations aren't moved, since all current migrations depend on other models that aren't
going to be moved.
In the community site we run an initial migration,
for the corporate site we run a fake migration.
Comment on lines +111 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we going to have different migrations files for the same organizations app if it will be same code base?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The models are already created on the commercial site, we can't run the migrations there again. We can remove the old migration files on the commercial site after the migration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just run the migrations on the community site without removing any migration file? When all these migrations are ran in the corporate site as well, they will do nothing.

Copy link
Member Author

@stsewd stsewd Oct 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app is different and the migration files from .com depend on other models and migrations that aren't on .org.

Copy link
Member

@ericholscher ericholscher Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the plan is to just squash the migrations and start with the current state as initial. This makes sense to me, as nobody will be needing to catch up to the current state, and it's effectively a new app in the .org.


For managers and querysets that depend on subscriptions,
we can use our pattern to make overridable classes (inheriting from ``SettingsOverrideObject``).

Templates, urls, views, forms, notifications, signals, tasks can be moved later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to have a bit more of this fleshed out. I think that moving the models is definitely the best first step, but it won't do us much good without migrating the queryset permission logic as well.

(we just need to make use of the models from the ``readthedocs.organizations`` module).

If we decide to integrate organizations in the community site,
we can enable the app.

After the app is moved,
we can move more code that depends on organizations to the community site.

Namespace
---------

Currently we use the project's slug as namespace,
in the commercial site we use the combination of ``organization.slug`` + ``project.slug`` as namespace.

For the community site probably this approach isn't the best,
since we always serve docs publicly from ``slug.readthedocs.io``.
And most of the users don't have a custom domain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is our plan for slugs for organization projects in community then? Are we not using the organization slug at all? I have concerns about supporting both patterns at once. A collision is introduced if you slug a project with slug foo-something and an organization project for organization slug foo and project name something -- ie both produce the same slug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting to use the project slug for users and orgs for .org. So we have foo-something and something.

Copy link
Member Author

@stsewd stsewd Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like if a user from the pallets org creates a project named flask, the slug would be flask, no pallets-flask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'd agree, that seems like a good pattern for the community side.


We could keep the current behavior for the community site and use ``organization.slug`` + ``project.slug`` for the corporate site,
since in the corporate site we don't care so much about a unique namespace between all users, but a unique namespace per organization.
We can refactor the way we get the namespace to be more easy to manage in both sites.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think we will need to keep both namespaces, since we don't want to break existing URL's. It should be simple enough to support by just changing the logic around slug creation.


Future Changes
--------------

Changes that aren't needed immediately after the migration,
but that should be done:

Edit the current querysets, modify/add UI elements, and add new endpoints to the API (v3 only).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the UI is not going to be a future change, it will be tied directly to this work. We should probably have an idea of at least what UI components are likely to require changes. We won't be able to just copy the UI bits into community as we've discussed structural changes -- supporting user projects and organization projects for instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just put some pieces not sure if we want to copy most of the UI from .com or make something different (especially for listing and detail of orgs)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not going to enable this on the community site yet, and we're going to do a two step process -- move the code over, and then sometime later actually enable organizations on the community codebase -- then we can worry about UI later.

Do we want to source templates for organizations from the commercial repo or move to the community repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a two step migration.

Do we want to source templates for organizations from the commercial repo or move to the community repo?

Good question, I think we can move the urls/views later, that way the templates can live in .com in the meantime and is easy to not enable organization in the community site.