Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (2)
(feat): enforce vote permissions
· e4bd4e81
Marcelo Rivera
authored
Oct 04, 2019
e4bd4e81
(feat): enforce DELETE_CHANNEL permission
· 94f507a7
Marcelo Rivera
authored
Oct 04, 2019
94f507a7
Hide whitespace changes
Inline
Side-by-side
src/app/common/components/thumbs/thumbs-down.component.ts
View file @
94f507a7
...
...
@@ -3,19 +3,22 @@ import {
ChangeDetectorRef
,
Component
,
DoCheck
,
Input
,
}
from
'
@angular/core
'
;
import
{
Session
}
from
'
../../../services/session
'
;
import
{
Client
}
from
'
../../../services/api
'
;
import
{
WalletService
}
from
'
../../../services/wallet
'
;
import
{
SignupModalService
}
from
'
../../../modules/modals/signup/service
'
;
import
{
Flags
}
from
'
../../services/permissions/flags
'
;
import
{
PermissionsService
}
from
'
../../services/permissions/permissions.service
'
;
import
{
FeaturesService
}
from
'
../../../services/features.service
'
;
@
Component
({
selector
:
'
minds-button-thumbs-down
'
,
inputs
:
[
'
_object: object
'
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
template
:
`
<a (click)="thumb()" [ngClass]="{ selected: has() }">
<a (click)="thumb()" [ngClass]="{ selected: has()
, disabled: !enabled
}">
<i class="material-icons">thumb_down</i>
<span class="minds-counter" *ngIf="object['thumbs:down:count'] > 0">{{
object['thumbs:down:count'] | number
...
...
@@ -34,19 +37,35 @@ export class ThumbsDownButton implements DoCheck {
changesDetected
:
boolean
=
false
;
object
;
showModal
:
boolean
=
false
;
enabled
:
boolean
=
true
;
constructor
(
private
cd
:
ChangeDetectorRef
,
public
session
:
Session
,
public
client
:
Client
,
public
wallet
:
WalletService
,
private
modal
:
SignupModalService
private
modal
:
SignupModalService
,
private
permissionsService
:
PermissionsService
,
private
featuresService
:
FeaturesService
)
{}
set
_object
(
value
:
any
)
{
@
Input
(
'
object
'
)
set
_object
(
value
:
any
)
{
this
.
object
=
value
;
if
(
!
this
.
object
[
'
thumbs:down:user_guids
'
])
this
.
object
[
'
thumbs:down:user_guids
'
]
=
[];
this
.
checkPermissions
();
}
private
checkPermissions
()
{
if
(
this
.
featuresService
.
has
(
'
permissions
'
))
{
this
.
enabled
=
this
.
permissionsService
.
canInteract
(
this
.
object
,
Flags
.
VOTE
);
}
else
{
this
.
enabled
=
true
;
}
}
thumb
()
{
...
...
src/app/common/components/thumbs/thumbs-up.component.ts
View file @
94f507a7
...
...
@@ -4,19 +4,22 @@ import {
Component
,
DoCheck
,
OnChanges
,
Input
,
}
from
'
@angular/core
'
;
import
{
Session
}
from
'
../../../services/session
'
;
import
{
Client
}
from
'
../../../services/api
'
;
import
{
WalletService
}
from
'
../../../services/wallet
'
;
import
{
SignupModalService
}
from
'
../../../modules/modals/signup/service
'
;
import
{
Flags
}
from
'
../../services/permissions/flags
'
;
import
{
PermissionsService
}
from
'
../../services/permissions/permissions.service
'
;
import
{
FeaturesService
}
from
'
../../../services/features.service
'
;
@
Component
({
selector
:
'
minds-button-thumbs-up
'
,
inputs
:
[
'
_object: object
'
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
template
:
`
<a (click)="thumb()" [ngClass]="{ selected: has() }">
<a (click)="thumb()" [ngClass]="{ selected: has()
, disabled: !enabled
}">
<i class="material-icons">thumb_up</i>
<span class="minds-counter" *ngIf="object['thumbs:up:count'] > 0">{{
object['thumbs:up:count'] | number
...
...
@@ -39,20 +42,36 @@ export class ThumbsUpButton implements DoCheck, OnChanges {
'
thumbs:up:user_guids
'
:
[],
};
showModal
:
boolean
=
false
;
enabled
:
boolean
=
true
;
constructor
(
public
session
:
Session
,
public
client
:
Client
,
public
wallet
:
WalletService
,
private
modal
:
SignupModalService
,
private
permissionsService
:
PermissionsService
,
private
featuresService
:
FeaturesService
,
private
cd
:
ChangeDetectorRef
)
{}
set
_object
(
value
:
any
)
{
@
Input
(
'
object
'
)
set
_object
(
value
:
any
)
{
if
(
!
value
)
return
;
this
.
object
=
value
;
if
(
!
this
.
object
[
'
thumbs:up:user_guids
'
])
this
.
object
[
'
thumbs:up:user_guids
'
]
=
[];
this
.
checkPermissions
();
}
private
checkPermissions
()
{
if
(
this
.
featuresService
.
has
(
'
permissions
'
))
{
this
.
enabled
=
this
.
permissionsService
.
canInteract
(
this
.
object
,
Flags
.
VOTE
);
}
else
{
this
.
enabled
=
true
;
}
}
thumb
()
{
...
...
@@ -62,6 +81,10 @@ export class ThumbsUpButton implements DoCheck, OnChanges {
return
false
;
}
if
(
!
this
.
enabled
)
{
return
;
}
this
.
client
.
put
(
'
api/v1/thumbs/
'
+
this
.
object
.
guid
+
'
/up
'
,
{});
if
(
!
this
.
has
())
{
//this.object['thumbs:up:user_guids'].push(this.session.getLoggedInUser().guid);
...
...
src/app/modules/settings/disable/disable.component.html
View file @
94f507a7
...
...
@@ -11,6 +11,7 @@
<button
class=
"mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-color--red"
(click)=
"disable()"
[disabled]=
"!enabled"
>
<ng-container
i18n=
"@@MINDS__SETTINGS__DISABLE_CONFIRM"
>
I'm sure - Disable
</ng-container
...
...
@@ -30,6 +31,7 @@
<button
class=
"mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-color--red"
(click)=
"delete()"
[disabled]=
"!enabled"
>
<ng-container
i18n=
"@@MINDS__SETTINGS__DELETE_CONFIRM"
>
I'm sure - Delete
</ng-container
...
...
src/app/modules/settings/disable/disable.component.ts
View file @
94f507a7
import
{
Component
}
from
'
@angular/core
'
;
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Router
}
from
'
@angular/router
'
;
import
{
Client
}
from
'
../../../services/api
'
;
import
{
OverlayModalService
}
from
'
../../../services/ux/overlay-modal
'
;
import
{
ConfirmPasswordModalComponent
}
from
'
../../modals/confirm-password/modal.component
'
;
import
{
PermissionsService
}
from
'
../../../common/services/permissions/permissions.service
'
;
import
{
FeaturesService
}
from
'
../../../services/features.service
'
;
import
{
Flags
}
from
'
../../../common/services/permissions/flags
'
;
import
{
Session
}
from
'
../../../services/session
'
;
@
Component
({
moduleId
:
module
.
id
,
...
...
@@ -11,20 +15,28 @@ import { ConfirmPasswordModalComponent } from '../../modals/confirm-password/mod
inputs
:
[
'
object
'
],
templateUrl
:
'
disable.component.html
'
,
})
export
class
SettingsDisableChannelComponent
{
export
class
SettingsDisableChannelComponent
implements
OnInit
{
minds
:
Minds
;
user
:
any
;
settings
:
string
;
object
:
any
;
enabled
:
boolean
=
true
;
constructor
(
public
client
:
Client
,
public
router
:
Router
,
private
overlayModal
:
OverlayModalService
private
overlayModal
:
OverlayModalService
,
private
session
:
Session
,
private
permissionsService
:
PermissionsService
,
private
featuresService
:
FeaturesService
)
{
this
.
minds
=
window
.
Minds
;
}
ngOnInit
()
{
this
.
checkPermissions
();
}
disable
()
{
this
.
client
.
delete
(
'
api/v1/channel
'
)
...
...
@@ -63,4 +75,15 @@ export class SettingsDisableChannelComponent {
);
creator
.
present
();
}
private
checkPermissions
()
{
if
(
this
.
featuresService
.
has
(
'
permissions
'
))
{
this
.
enabled
=
this
.
permissionsService
.
canInteract
(
this
.
session
.
getLoggedInUser
(),
Flags
.
DELETE_CHANNEL
);
}
else
{
this
.
enabled
=
true
;
}
}
}