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 (5)
(feat) add FLAG_VIEW check and code cleaning in group screen
· 50d4a8f3
Martin Santangelo
authored
Oct 10, 2019
50d4a8f3
(feat) add FLAG_VIEW check to groups in the discovery screen
· f50f9a4d
Martin Santangelo
authored
Oct 10, 2019
f50f9a4d
(feat) add FLAG_VIEW check in blog view screen
· 4212fd06
Martin Santangelo
authored
Oct 10, 2019
4212fd06
(fix) gathering service FLAG_JOIN_GATHERING check
· 401ccd09
Martin Santangelo
authored
Oct 10, 2019
401ccd09
(feat) permissions behind a feature flag
· 28c29bf8
Martin Santangelo
authored
Oct 10, 2019
28c29bf8
Hide whitespace changes
Inline
Side-by-side
src/auth/UserStore.js
View file @
28c29bf8
...
...
@@ -73,7 +73,7 @@ class UserStore {
}
isAdmin
()
{
return
this
.
me
.
a
dmin
;
return
this
.
me
.
isA
dmin
()
;
}
@
action
...
...
src/blogs/BlogsViewScreen.js
View file @
28c29bf8
...
...
@@ -47,6 +47,7 @@ import CenteredLoading from '../common/components/CenteredLoading';
import
logService
from
'
../common/services/log.service
'
;
import
i18n
from
'
../common/services/i18n.service
'
;
import
featuresService
from
'
../common/services/features.service
'
;
import
{
FLAG_VIEW
}
from
'
../common/Permissions
'
;
/**
* Blog View Screen
...
...
@@ -100,7 +101,7 @@ export default class BlogsViewScreen extends Component {
this
.
props
.
blogsView
.
reset
();
let
guid
;
if
(
params
.
slug
)
{
guid
=
params
.
slug
.
substr
(
params
.
slug
.
lastIndexOf
(
'
-
'
)
+
1
);
guid
=
params
.
slug
.
substr
(
params
.
slug
.
lastIndexOf
(
'
-
'
)
+
1
);
}
else
{
guid
=
params
.
guid
;
}
...
...
@@ -108,6 +109,12 @@ export default class BlogsViewScreen extends Component {
await
this
.
props
.
blogsView
.
loadBlog
(
guid
);
}
// check permissions
if
(
!
this
.
props
.
blogsView
.
blog
.
can
(
FLAG_VIEW
,
true
))
{
this
.
props
.
navigation
.
goBack
();
return
;
}
if
(
this
.
props
.
blogsView
.
blog
&&
this
.
props
.
blogsView
.
blog
.
_list
)
{
this
.
props
.
blogsView
.
blog
.
_list
.
viewed
.
addViewed
(
this
.
props
.
blogsView
.
blog
,
...
...
src/channel/ChannelActions.js
View file @
28c29bf8
...
...
@@ -130,7 +130,8 @@ class ChannelActions extends Component {
const
showWire
=
!
channel
.
blocked
&&
!
isOwner
&&
featuresService
.
has
(
'
crypto
'
)
&&
channel
.
can
(
FLAG_WIRE
);
const
showScheduled
=
featuresService
.
has
(
'
post-scheduler
'
)
&&
!
this
.
state
.
edit
&&
isOwner
;
const
showSubscribe
=
!
isOwner
&&
!
channel
.
subscribed
&&
channel
.
can
(
FLAG_SUBSCRIBE
);
const
showMessage
=
!
isOwner
&&
channel
.
can
(
FLAG_MESSAGE
);
const
showMessage
=
!
isOwner
&&
channel
.
subscribed
&&
channel
.
can
(
FLAG_MESSAGE
);
const
showEdit
=
isOwner
&&
channel
.
can
(
FLAG_EDIT_CHANNEL
);
if
(
this
.
props
.
store
.
isUploading
)
{
return
(
...
...
@@ -165,7 +166,7 @@ class ChannelActions extends Component {
text
=
{
i18n
.
t
(
'
channel.message
'
)}
/
>
}
{
channel
.
can
(
FLAG_EDIT_CHANNEL
)
&&
{
showEdit
&&
<
ButtonCustom
onPress
=
{
this
.
onEditAction
}
containerStyle
=
{[
CS
.
rowJustifyCenter
,
CS
.
marginLeft0x
]}
...
...
src/channel/UserModel.js
View file @
28c29bf8
...
...
@@ -64,6 +64,13 @@ export default class UserModel extends BaseModel {
}
}
/**
* Is admin
*/
isAdmin
()
{
return
!!
this
.
admin
;
}
/**
* current user is owner of the channel
*/
...
...
src/comments/CommentActionSheet.js
View file @
28c29bf8
...
...
@@ -5,6 +5,8 @@ import React, {
import
ActionSheet
from
'
react-native-actionsheet
'
;
import
i18n
from
'
../common/services/i18n.service
'
;
import
{
FLAG_EDIT_COMMENT
,
FLAG_DELETE_COMMENT
,
FLAG_CREATE_COMMENT
}
from
'
../common/Permissions
'
;
import
featuresService
from
'
../common/services/features.service
'
;
import
sessionService
from
'
../common/services/session.service
'
;
/**
* Comment Component
...
...
@@ -44,28 +46,60 @@ export default class CommentActionSheet extends Component {
const
comment
=
this
.
props
.
comment
;
if
(
comment
.
can
(
FLAG_EDIT_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
edit
'
)
);
if
(
!
comment
.
mature
)
{
actions
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
actions
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
// TODO: clean up permissions feature flag
if
(
featuresService
.
has
(
'
permissions
'
))
{
if
(
comment
.
can
(
FLAG_EDIT_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
edit
'
)
);
if
(
!
comment
.
mature
)
{
actions
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
actions
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
}
}
}
if
(
comment
.
can
(
FLAG_DELETE_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
delete
'
)
);
}
if
(
comment
.
can
(
FLAG_DELETE_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
delete
'
)
);
}
if
(
comment
.
parent_guid_l2
==
0
&&
comment
.
can
(
FLAG_CREATE_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
rep
ly
'
)
);
}
if
(
!
comment
.
isOwner
(
))
{
actions
.
push
(
i18n
.
t
(
'
rep
ort
'
)
);
}
if
(
!
comment
.
isOwner
())
{
actions
.
push
(
i18n
.
t
(
'
report
'
)
);
actions
.
push
(
i18n
.
t
(
'
copy
'
)
);
if
(
comment
.
parent_guid_l2
==
0
&&
comment
.
can
(
FLAG_CREATE_COMMENT
))
{
actions
.
push
(
i18n
.
t
(
'
reply
'
)
);
}
}
else
{
if
(
comment
.
isOwner
())
{
actions
.
push
(
i18n
.
t
(
'
edit
'
)
);
actions
.
push
(
i18n
.
t
(
'
delete
'
)
);
if
(
!
comment
.
mature
)
{
actions
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
actions
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
}
}
else
{
if
(
sessionService
.
getUser
().
isAdmin
())
{
actions
.
push
(
i18n
.
t
(
'
delete
'
)
);
if
(
!
comment
.
mature
)
{
actions
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
actions
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
)
}
}
actions
.
push
(
i18n
.
t
(
'
report
'
)
);
actions
.
push
(
i18n
.
t
(
'
copy
'
)
);
}
if
(
comment
.
parent_guid_l2
==
0
)
{
actions
.
push
(
i18n
.
t
(
'
reply
'
)
);
}
}
actions
.
push
(
i18n
.
t
(
'
copy
'
)
);
return
actions
;
}
...
...
src/common/BaseModel.js
View file @
28c29bf8
...
...
@@ -15,6 +15,7 @@ import channelService from '../channel/ChannelService';
import
{
revokeBoost
,
acceptBoost
,
rejectBoost
}
from
'
../boost/BoostService
'
;
import
{
toggleAllowComments
as
toggleAllow
}
from
'
../comments/CommentsService
'
;
import
i18n
from
'
./services/i18n.service
'
;
import
featuresService
from
'
./services/features.service
'
;
/**
* Base model
...
...
@@ -302,6 +303,9 @@ export default class BaseModel {
*/
can
(
action
,
showAlert
=
false
)
{
// TODO: clean up permissions feature flag
if
(
!
featuresService
.
has
(
'
permissions
'
))
return
true
;
let
allowed
=
true
;
if
(
!
this
.
permissions
||
!
this
.
permissions
.
permissions
)
{
...
...
src/common/services/gathering.service.js
View file @
28c29bf8
...
...
@@ -22,7 +22,7 @@ class GatheringService {
*/
@
action
async
join
(
entity
)
{
if
(
this
.
isActive
||
entity
.
can
(
FLAG_JOIN_GATHERING
))
{
if
(
this
.
isActive
||
!
entity
.
can
(
FLAG_JOIN_GATHERING
))
{
return
;
}
try
{
...
...
src/discovery/DiscoveryScreen.js
View file @
28c29bf8
...
...
@@ -47,6 +47,7 @@ import DiscoveryFilters from './NewsfeedFilters';
import
ErrorBoundary
from
'
../common/components/ErrorBoundary
'
;
import
testID
from
'
../common/helpers/testID
'
;
import
i18n
from
'
../common/services/i18n.service
'
;
import
{
FLAG_VIEW
}
from
'
../common/Permissions
'
;
const
isIos
=
Platform
.
OS
===
'
ios
'
;
...
...
@@ -588,6 +589,10 @@ export default class DiscoveryScreen extends Component {
}
navigateToGroup
=
(
group
)
=>
{
if
(
!
group
.
can
(
FLAG_VIEW
,
true
))
{
return
;
}
this
.
props
.
navigation
.
push
(
'
GroupView
'
,
{
group
:
group
})
}
}
...
...
src/groups/GroupViewScreen.js
View file @
28c29bf8
...
...
@@ -38,7 +38,7 @@ import commentsStoreProvider from '../comments/CommentsStoreProvider';
import
i18n
from
'
../common/services/i18n.service
'
;
import
featuresService
from
'
../common/services/features.service
'
;
import
FeedList
from
'
../common/components/FeedList
'
;
import
{
FLAG_CREATE_POST
,
FLAG_APPOINT_MODERATOR
}
from
'
../common/Permissions
'
;
import
{
FLAG_CREATE_POST
,
FLAG_APPOINT_MODERATOR
,
FLAG_VIEW
}
from
'
../common/Permissions
'
;
/**
* Groups view screen
...
...
@@ -82,20 +82,11 @@ export default class GroupViewScreen extends Component {
}
/**
*
On component will mount
*
Load initial data
*/
async
componentWillMount
()
{
async
initialLoad
()
{
const
params
=
this
.
props
.
navigation
.
state
.
params
;
this
.
disposeEnter
=
this
.
props
.
navigation
.
addListener
(
'
didFocus
'
,
(
s
)
=>
{
const
params
=
this
.
props
.
navigation
.
state
.
params
;
if
(
params
&&
params
.
prepend
)
{
this
.
props
.
groupView
.
prepend
(
params
.
prepend
);
// we clear the parameter to prevent prepend it again on goBack
this
.
props
.
navigation
.
setParams
({
prepend
:
null
});
}
});
if
(
params
.
group
)
{
// load group and update async
await
this
.
props
.
groupView
.
loadGroup
(
params
.
group
);
...
...
@@ -111,18 +102,37 @@ export default class GroupViewScreen extends Component {
// load feed
this
.
props
.
groupView
.
loadFeed
();
}
// check permissions
if
(
!
this
.
props
.
groupView
.
group
.
can
(
FLAG_VIEW
,
true
))
{
this
.
props
.
navigation
.
goBack
();
return
;
}
this
.
props
.
groupView
.
loadTopMembers
();
}
componentDidMount
()
{
const
navParams
=
this
.
props
.
navigation
.
state
.
params
;
const
params
=
this
.
props
.
navigation
.
state
.
params
;
// load data async
this
.
initialLoad
();
this
.
disposeEnter
=
this
.
props
.
navigation
.
addListener
(
'
didFocus
'
,
(
s
)
=>
{
const
params
=
this
.
props
.
navigation
.
state
.
params
;
if
(
params
&&
params
.
prepend
)
{
this
.
props
.
groupView
.
prepend
(
params
.
prepend
);
// we clear the parameter to prevent prepend it again on goBack
this
.
props
.
navigation
.
setParams
({
prepend
:
null
});
}
});
if
(
navP
arams
&&
navP
arams
.
prepend
)
{
this
.
props
.
groupView
.
prepend
(
navP
arams
.
prepend
);
if
(
p
arams
&&
p
arams
.
prepend
)
{
this
.
props
.
groupView
.
prepend
(
p
arams
.
prepend
);
}
if
(
navP
arams
.
tab
&&
this
.
headerRef
)
{
this
.
headerRef
.
wrappedInstance
.
onTabChange
(
navP
arams
.
tab
)
if
(
p
arams
.
tab
&&
this
.
headerRef
)
{
this
.
headerRef
.
wrappedInstance
.
onTabChange
(
p
arams
.
tab
)
}
}
...
...
src/newsfeed/activity/ActivityActionSheet.js
View file @
28c29bf8
...
...
@@ -20,6 +20,7 @@ import i18n from '../../common/services/i18n.service';
import
featuresService
from
'
../../common/services/features.service
'
;
import
translationService
from
'
../../common/services/translation.service
'
;
import
{
FLAG_EDIT_POST
,
FLAG_DELETE_POST
}
from
'
../../common/Permissions
'
;
import
sessionService
from
'
../../common/services/session.service
'
;
/**
* Activity Actions Component
...
...
@@ -60,56 +61,108 @@ export default class ActivityActionSheet extends Component {
let
options
=
[
i18n
.
t
(
'
cancel
'
)
];
const
entity
=
this
.
props
.
entity
;
// if can edit
if
(
entity
.
can
(
FLAG_EDIT_POST
))
{
options
.
push
(
i18n
.
t
(
'
edit
'
)
);
// TODO: remove feature flag
if
(
featuresService
.
has
(
'
permissions
'
))
{
// if can edit
if
(
entity
.
can
(
FLAG_EDIT_POST
))
{
options
.
push
(
i18n
.
t
(
'
edit
'
)
);
if
(
!
entity
.
mature
)
{
options
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
if
(
!
entity
.
mature
)
{
options
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
}
if
(
!
entity
.
dontPin
)
{
if
(
!
entity
.
pinned
)
{
options
.
push
(
i18n
.
t
(
'
pin
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unpin
'
)
);
}
}
if
(
featuresService
.
has
(
'
allow-comments-toggle
'
))
{
options
.
push
(
entity
.
allow_comments
?
i18n
.
t
(
'
disableComments
'
)
:
i18n
.
t
(
'
enableComments
'
));
}
}
if
(
translationService
.
isTranslatable
(
entity
))
{
options
.
push
(
i18n
.
t
(
'
translate.translate
'
)
);
}
if
(
!
entity
.
dontPin
)
{
if
(
!
entity
.
pinned
)
{
options
.
push
(
i18n
.
t
(
'
pin
'
)
);
// if is not the owner
if
(
!
entity
.
isOwner
())
{
options
.
push
(
i18n
.
t
(
'
report
'
)
);
if
(
this
.
state
&&
this
.
state
.
userBlocked
)
{
options
.
push
(
i18n
.
t
(
'
channel.unblock
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unpin
'
)
);
options
.
push
(
i18n
.
t
(
'
channel.block
'
)
);
}
}
if
(
featuresService
.
has
(
'
allow-comments-toggle
'
))
{
options
.
push
(
entity
.
allow_comments
?
i18n
.
t
(
'
disableComments
'
)
:
i18n
.
t
(
'
enableComments
'
));
options
.
push
(
i18n
.
t
(
'
share
'
)
);
if
(
!
entity
[
'
is:following
'
])
{
options
.
push
(
i18n
.
t
(
'
follow
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unfollow
'
)
);
}
}
if
(
translationService
.
isTranslatable
(
entity
))
{
options
.
push
(
i18n
.
t
(
'
translate.translate
'
)
);
}
// if can delete
if
(
entity
.
can
(
FLAG_DELETE_POST
))
{
options
.
push
(
<
Text
style
=
{[
CS
.
colorDanger
,
CS
.
fontXL
]}
>
{
i18n
.
t
(
'
delete
'
)}
<
/Text>
)
;
}
}
else
{
// if can edit
if
(
entity
.
isOwner
())
{
options
.
push
(
i18n
.
t
(
'
edit
'
)
);
// if is not the owner
if
(
!
entity
.
isOwner
())
{
options
.
push
(
i18n
.
t
(
'
report
'
)
);
if
(
!
entity
.
mature
)
{
options
.
push
(
i18n
.
t
(
'
setExplicit
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
removeExplicit
'
)
);
}
if
(
this
.
state
&&
this
.
state
.
userBlocked
)
{
options
.
push
(
i18n
.
t
(
'
channel.unblock
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
channel.block
'
)
);
if
(
!
entity
.
dontPin
)
{
if
(
!
entity
.
pinned
)
{
options
.
push
(
i18n
.
t
(
'
pin
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unpin
'
)
);
}
}
if
(
featuresService
.
has
(
'
allow-comments-toggle
'
))
{
options
.
push
(
entity
.
allow_comments
?
i18n
.
t
(
'
disableComments
'
)
:
i18n
.
t
(
'
enableComments
'
));
}
}
}
options
.
push
(
i18n
.
t
(
'
share
'
)
);
if
(
translationService
.
isTranslatable
(
entity
))
{
options
.
push
(
i18n
.
t
(
'
translate.translate
'
)
);
}
if
(
!
entity
[
'
is:following
'
])
{
options
.
push
(
i18n
.
t
(
'
follow
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unfollow
'
)
);
}
// if is not the owner
if
(
!
entity
.
isOwner
())
{
options
.
push
(
i18n
.
t
(
'
report
'
)
);
if
(
this
.
state
&&
this
.
state
.
userBlocked
)
{
options
.
push
(
i18n
.
t
(
'
channel.unblock
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
channel.block
'
)
);
}
}
options
.
push
(
i18n
.
t
(
'
share
'
)
);
if
(
!
entity
[
'
is:following
'
])
{
options
.
push
(
i18n
.
t
(
'
follow
'
)
);
}
else
{
options
.
push
(
i18n
.
t
(
'
unfollow
'
)
);
}
// if can delete
if
(
entity
.
can
(
FLAG_DELETE_POST
))
{
if
(
entity
.
isOwner
()
||
sessionService
.
getUser
().
isAdmin
(
))
{
options
.
push
(
<
Text
style
=
{[
CS
.
colorDanger
,
CS
.
fontXL
]}
>
{
i18n
.
t
(
'
delete
'
)}
<
/Text>
)
;
}
}
return
options
;
}
...
...