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

Allow personal teams to be optional #910

Conversation

skulls-dot-codes
Copy link

The PR makes personal teams still default on a new install but has the option of disabling. This will allow a broader use of this package where registering a user doesn't create a personal team. This behavior is controlled by the config/jetstream.php file:

Features::teams(['personal' => true, 'invitations' => true]),

The default behavior on a new install is unchanged. When enabled, personal teams still cannot be deleted. When disabled, no personal team is created at the time of user registration and allows the user to not be a member of any team. Team creation is still controlled by the create team gate in both cases. Both inertia and livewire templates have been updated and all tests pass.

The installer should decide during activation of the teams feature if this option should be enabled or disabled.

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@lostdesign
Copy link
Contributor

@taylorotwell the PR to me seemed high valuable, bringing in a config options just like you'd expect in fortify.

Despite that the test could be extended rather then skipping if there is no personal team desired, it should still be a first party solution and not a community package.

Disabling a personal team isn't much of a change code wise, most that was done was replacing wether the team is desired over a hardcoded true.

I'd love if you could reconsider checking this PR. If necessary I am more than willing to help OP to write the tests for the non-personal-team option.

@kyranb
Copy link

kyranb commented Nov 30, 2021

Just going to chime in and say too, across a variety of SaaS apps, this is the most common use case. Where someone is a team owner and wants to invite a 'teammate', without creating their own team/tenant at the same time.

If this decision can be re-considered it would make Jetstream much more versatile :)

@alesf
Copy link

alesf commented Nov 30, 2021

It's kind of restricting if you can't disable personal teams.
Not every app fits in this flow of managing teams.
I really miss this option for when I want only admins to have control over team management and creating user roles.

@RhysLees
Copy link
Contributor

RhysLees commented Nov 30, 2021

I think this needs to be reconsidered. I have been working on 5 or 6 websites now that use jetstream and only one of them have required a personal team, while the rest of them only needed to have teams optionally. in the end, for them, we ended up just disabling teams and adding in our own integration but it would be 1000x better having an optional team without personal teams in jetstream natively.

@MCKLtech
Copy link

Chiming in as others have said, personal teams make no sense and I'd welcome an explanation as to why they are mandatory. It is a poor design decision that has now got out hand?

I've never come across a system that works in this manner. If I create a team and ask people to join, they join my team directly.

@skulls-dot-codes
Copy link
Author

@taylorotwell if this PR isn't going to be merged then can we get this feature in the near future?

@lnfel
Copy link

lnfel commented Dec 15, 2021

I just implemented similar case by changing Fortify actions provided by Jetstream, in my case users can only be created through a valid invitation.
Helpful article: https://devlan.io/disabling-personal-teams-in-laravel-8-and-jetstream-1fd083593e08/

I highly think that having Personal team to be optional is needed as explained by top comments.

// in App\Actions\Fortify\CreateNewUser

use App\Models\TeamInvitation;
use Laravel\Jetstream\Contracts\AddsTeamMembers;

class CreateNewUser implements CreatesNewUsers
{
    public function create(array $input)
    {
        Validator::make($input, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users', 'exists:team_invitations'],
            'password' => $this->passwordRules(),
            'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',
        ],
        [
            'email.exists' => 'Can only register using invited email.',
        ])->validate();
    
        return DB::transaction(function () use ($input) {
            return tap(User::create([
                'name' => $input['name'],
                'email' => $input['email'],
                'password' => Hash::make($input['password']),
            ]), function (User $user) {
                // Disable creating personal team for each user
                //$this->createTeam($user);
    
                $invitation = TeamInvitation::where('email', $user->email)->first();
                $this->assignTeam($user, $invitation);
            });
        });
    }
    
    protected function assignTeam(User $user, TeamInvitation $invitation)
    {
        app(AddsTeamMembers::class)->add(
            $invitation->team->owner,
            $invitation->team,
            $invitation->email,
            $invitation->role
        );
    
        $user->current_team_id = $invitation->team_id;
        $user->save();
    }
}

@a2sc
Copy link

a2sc commented May 14, 2023

The link to the article mentioned above has moved to: https://npratley.net/disabling-personal-teams-in-laravel-8-and-jetstream-1fd083593e08/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants