sozsoft-platform/configs/seeds/sql/object/Hr_S_PerformanceGuard.sql
2026-10-05 15:58:59 +03:00

54 lines
No EOL
2.6 KiB
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE OR ALTER PROCEDURE [dbo].[Hr_S_PerformanceGuard]
@ReviewId uniqueidentifier,
@UserId uniqueidentifier,
@Actor nvarchar(16),
@Scope nvarchar(16),
@FeedbackId uniqueidentifier = NULL
AS
BEGIN
SET NOCOUNT ON;
-- Kişisel ekranlar (Değerlendirmelerim, Ekibim, 360 Taleplerim) satırı listede süzer; bu kontrol
-- aynı kuralı yazma tarafında uygular. Kayıt uçları satırı yalnızca Id ile güncellediği için
-- başka birinin kaydına doğrudan yapılan istek burada reddedilir.
IF @Actor = N'Hr'
RETURN;
DECLARE @Status nvarchar(16), @EmployeeId uniqueidentifier, @ManagerId uniqueidentifier, @PeriodStatus nvarchar(16);
SELECT @Status = rv.Status, @EmployeeId = rv.EmployeeId, @ManagerId = rv.ManagerId, @PeriodStatus = p.Status
FROM Hr_T_PerformanceReview rv
INNER JOIN Hr_T_PerformancePeriod p ON p.Id = rv.PeriodId
WHERE rv.Id = @ReviewId AND rv.IsDeleted = 0;
IF @Status IS NULL
THROW 51000, N'Değerlendirme kaydı bulunamadı.', 1;
IF @PeriodStatus = N'Closed'
THROW 51001, N'Dönem kapatıldığı için değerlendirme değiştirilemez.', 1;
IF @Actor = N'Employee' AND (@UserId IS NULL OR @UserId <> @EmployeeId)
THROW 51002, N'Yalnızca kendi değerlendirmenizi değiştirebilirsiniz.', 1;
IF @Actor = N'Manager' AND (@UserId IS NULL OR @ManagerId IS NULL OR @UserId <> @ManagerId)
THROW 51003, N'Yalnızca yöneticisi olduğunuz değerlendirmeleri değiştirebilirsiniz.', 1;
IF @Actor = N'Reviewer' AND NOT EXISTS (
SELECT 1 FROM Hr_T_PerformanceFeedback f
WHERE f.Id = @FeedbackId AND f.ReviewId = @ReviewId AND f.ReviewerId = @UserId AND f.IsDeleted = 0)
THROW 51004, N'Yalnızca size atanan 360 değerlendirmesini doldurabilirsiniz.', 1;
-- Durum matrisi: hangi rol hangi aşamada neyi değiştirebilir.
DECLARE @Allowed bit = CASE
WHEN @Scope = N'DevelopmentPlan' THEN 1
WHEN @Actor = N'Employee' AND @Scope = N'Review' THEN IIF(@Status IN (N'GoalSetting', N'SelfReview'), 1, 0)
WHEN @Actor = N'Employee' AND @Scope IN (N'Goal', N'Competency') THEN IIF(@Status IN (N'GoalSetting', N'SelfReview'), 1, 0)
WHEN @Actor = N'Manager' AND @Scope IN (N'Review', N'Goal', N'Competency') THEN IIF(@Status IN (N'GoalSetting', N'SelfReview', N'ManagerReview'), 1, 0)
WHEN @Actor = N'Reviewer' THEN IIF(@Status IN (N'GoalSetting', N'SelfReview', N'ManagerReview'), 1, 0)
ELSE 0
END;
IF @Allowed = 0
THROW 51005, N'Değerlendirme bu aşamada bu işlem için açık değil.', 1;
END
GO