Added ability to set password for groups
• Added: - ability to set password for groups - GroupPasswordModal - checks for if has password - rate limiting in rack_attack
This commit is contained in:
38
app/controllers/api/v1/groups/password_controller.rb
Normal file
38
app/controllers/api/v1/groups/password_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Groups::PasswordController < Api::BaseController
|
||||
|
||||
include Authorization
|
||||
|
||||
before_action :require_user!
|
||||
before_action :set_group
|
||||
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
authorize @group, :join?
|
||||
|
||||
if params[:password] == @group.password
|
||||
if @group.is_private
|
||||
@group.join_requests << current_account
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
else
|
||||
@group.accounts << current_account
|
||||
render json: @group, serializer: REST::GroupRelationshipSerializer, relationships: relationships
|
||||
end
|
||||
else
|
||||
render json: { error: true, message: 'Invalid group password' }, status: 403
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_group
|
||||
@group = Group.find(params[:group_id])
|
||||
end
|
||||
|
||||
def relationships
|
||||
GroupRelationshipsPresenter.new([@group.id], current_user.account_id)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user